Blob Blame History Raw
From 5350d10ffc03c774e5cd574062297fc91001064d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dan=20Hor=C3=A1k?= <dan@danny.cz>
Date: Mon, 15 Apr 2019 07:35:00 -0400
Subject: [PATCH] fix reading files

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
---
 OpenEXR/IlmImfTest/testFutureProofing.cpp           | 8 ++++++++
 OpenEXR/IlmImfTest/testMultiPartFileMixingBasic.cpp | 7 +++++++
 2 files changed, 15 insertions(+)

diff --git a/OpenEXR/IlmImfTest/testFutureProofing.cpp b/OpenEXR/IlmImfTest/testFutureProofing.cpp
index 1b926868..b463c343 100644
--- a/OpenEXR/IlmImfTest/testFutureProofing.cpp
+++ b/OpenEXR/IlmImfTest/testFutureProofing.cpp
@@ -40,6 +40,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
+#include <byteswap.h>
 
 #include "tmpDir.h"
 #include "testFutureProofing.h"
@@ -64,6 +65,7 @@
 #include <ImfNamespace.h>
 #include <ImathNamespace.h>
 #include <IlmThreadNamespace.h>
+#include <ImfSystemSpecific.h>
 
 namespace IMF = OPENEXR_IMF_NAMESPACE;
 using namespace IMF;
@@ -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>'
diff --git a/OpenEXR/IlmImfTest/testMultiPartFileMixingBasic.cpp b/OpenEXR/IlmImfTest/testMultiPartFileMixingBasic.cpp
index 1fdb6319..41734ef3 100644
--- a/OpenEXR/IlmImfTest/testMultiPartFileMixingBasic.cpp
+++ b/OpenEXR/IlmImfTest/testMultiPartFileMixingBasic.cpp
@@ -40,6 +40,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
+#include <byteswap.h>
 
 #include "tmpDir.h"
 #include "testMultiPartFileMixingBasic.h"
@@ -59,6 +60,7 @@
 #include <ImfDeepScanLineInputPart.h>
 #include <ImfPartType.h>
 #include <ImfMisc.h>
+#include <ImfSystemSpecific.h>
 
 namespace IMF = OPENEXR_IMF_NAMESPACE;
 using namespace IMF;
@@ -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++) 
From 225ddb8777e75978b88c2d6311bb0cf94c0b6f22 Mon Sep 17 00:00:00 2001
From: Cary Phillips <cary@ilm.com>
Date: Tue, 2 Jul 2019 15:23:37 -0700
Subject: [PATCH] bswap_32 to correct endianness on read, to address #81.

Signed-off-by: Cary Phillips <cary@ilm.com>
---
 OpenEXR/IlmImfTest/Makefile.am                |  3 +-
 OpenEXR/IlmImfTest/bswap_32.h                 | 29 +++++++++++++++++++
 OpenEXR/IlmImfTest/testFutureProofing.cpp     |  5 ++--
 .../testMultiPartFileMixingBasic.cpp          |  6 ++--
 4 files changed, 36 insertions(+), 7 deletions(-)
 create mode 100644 OpenEXR/IlmImfTest/bswap_32.h

diff --git a/OpenEXR/IlmImfTest/Makefile.am b/OpenEXR/IlmImfTest/Makefile.am
index 36817c7e..06c3638a 100644
--- a/OpenEXR/IlmImfTest/Makefile.am
+++ b/OpenEXR/IlmImfTest/Makefile.am
@@ -51,7 +51,8 @@ IlmImfTest_SOURCES = main.cpp tmpDir.h testAttributes.cpp testChannels.cpp \
 		     testFutureProofing.cpp testFutureProofing.h \
 	             compareDwa.cpp compareDwa.h \
 	             testDwaCompressorSimd.cpp testDwaCompressorSimd.h \
-	             testRle.cpp testRle.h
+	             testRle.cpp testRle.h \
+		     bswap_32.h
 
 AM_CPPFLAGS = -DILM_IMF_TEST_IMAGEDIR=\"$(srcdir)/\"
 
diff --git a/OpenEXR/IlmImfTest/bswap_32.h b/OpenEXR/IlmImfTest/bswap_32.h
new file mode 100644
index 00000000..42962629
--- /dev/null
+++ b/OpenEXR/IlmImfTest/bswap_32.h
@@ -0,0 +1,29 @@
+//
+// SPDX-License-Identifier: Modified-BSD-3-Clause
+// Copyright Contributors to the OpenEXR Project. See LICENSE file for details.
+// 
+
+#ifdef _MSC_VER
+#include <stdlib.h>
+#define bswap_32(x) _byteswap_ulong(x)
+#elif defined(__APPLE__)
+#include <libkern/OSByteOrder.h>
+#define bswap_32(x) OSSwapInt32(x)
+#elif defined(__sun) || defined(sun)
+#include <sys/byteorder.h>
+#define bswap_32(x) BSWAP_32(x)
+#elif defined(__FreeBSD__)
+#include <sys/endian.h>
+#define bswap_32(x) bswap32(x)
+#elif defined(__OpenBSD__)
+#include <sys/types.h>
+#define bswap_32(x) swap32(x)
+#elif defined(__NetBSD__)
+#include <sys/types.h>
+#include <machine/bswap.h>
+#if defined(__BSWAP_RENAME) && !defined(__bswap_32)
+#define bswap_32(x) bswap32(x)
+#endif
+#else
+#include <byteswap.h>
+#endif
diff --git a/OpenEXR/IlmImfTest/testFutureProofing.cpp b/OpenEXR/IlmImfTest/testFutureProofing.cpp
index b463c343..05664b37 100644
--- a/OpenEXR/IlmImfTest/testFutureProofing.cpp
+++ b/OpenEXR/IlmImfTest/testFutureProofing.cpp
@@ -40,7 +40,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
-#include <byteswap.h>
+#include "bswap_32.h"
 
 #include "tmpDir.h"
 #include "testFutureProofing.h"
@@ -1238,8 +1238,7 @@ modifyType (bool modify_version)
             fread(&length,4,1,f);
             if (!GLOBAL_SYSTEM_LITTLE_ENDIAN)
             {
-                int tmp = bswap_32(length);
-        	length = tmp;
+        	length = bswap_32(length);
             }
 
             if(!modify_version && attrib_name=="type")
diff --git a/OpenEXR/IlmImfTest/testMultiPartFileMixingBasic.cpp b/OpenEXR/IlmImfTest/testMultiPartFileMixingBasic.cpp
index 41734ef3..da75a1f4 100644
--- a/OpenEXR/IlmImfTest/testMultiPartFileMixingBasic.cpp
+++ b/OpenEXR/IlmImfTest/testMultiPartFileMixingBasic.cpp
@@ -40,7 +40,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
-#include <byteswap.h>
+
+#include "bswap_32.h"
 
 #include "tmpDir.h"
 #include "testMultiPartFileMixingBasic.h"
@@ -1387,8 +1388,7 @@ killOffsetTables (const std::string & fn)
             fread(&length,4,1,f);
     	    if (!GLOBAL_SYSTEM_LITTLE_ENDIAN)
     	    {
-    		int tmp = bswap_32(length);
-    		length = tmp;
+    		length = bswap_32(length);
     	    }
             
             //value of attribute