Skip to content

Commit

Permalink
fix reading files
Browse files Browse the repository at this point in the history
testFutureProofing and testMultiPartFileMixingBasic both use fread(&length,4,f) to get a 4 byte
integer value from input file. The value read is not converted from the little endian format to
the machine format causing problems (eg. test didn't finish after 24 hours).

fixes issue #81
  • Loading branch information
sharkcz authored and cary-ilm committed Jul 12, 2019
1 parent 29d18b7 commit 5350d10
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions OpenEXR/IlmImfTest/testFutureProofing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <byteswap.h>

#include "tmpDir.h"
#include "testFutureProofing.h"
Expand All @@ -64,6 +65,7 @@
#include <ImfNamespace.h>
#include <ImathNamespace.h>
#include <IlmThreadNamespace.h>
#include <ImfSystemSpecific.h>

namespace IMF = OPENEXR_IMF_NAMESPACE;
using namespace IMF;
Expand Down Expand Up @@ -1234,6 +1236,12 @@ modifyType (bool modify_version)

//length of attribute
fread(&length,4,1,f);
if (!GLOBAL_SYSTEM_LITTLE_ENDIAN)
{
int tmp = bswap_32(length);
length = tmp;
}

if(!modify_version && attrib_name=="type")
{
// modify the type of part 1 to be 'X<whatevever>'
Expand Down
7 changes: 7 additions & 0 deletions OpenEXR/IlmImfTest/testMultiPartFileMixingBasic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <byteswap.h>

#include "tmpDir.h"
#include "testMultiPartFileMixingBasic.h"
Expand All @@ -59,6 +60,7 @@
#include <ImfDeepScanLineInputPart.h>
#include <ImfPartType.h>
#include <ImfMisc.h>
#include <ImfSystemSpecific.h>

namespace IMF = OPENEXR_IMF_NAMESPACE;
using namespace IMF;
Expand Down Expand Up @@ -1383,6 +1385,11 @@ killOffsetTables (const std::string & fn)

//length of attribute
fread(&length,4,1,f);
if (!GLOBAL_SYSTEM_LITTLE_ENDIAN)
{
int tmp = bswap_32(length);
length = tmp;
}

//value of attribute
for(int i=0;i<length;i++)
Expand Down

0 comments on commit 5350d10

Please sign in to comment.