From d239d1dc9e7eb5bf2797babfe165aa0dce2d67a3 Mon Sep 17 00:00:00 2001 From: Peter Hillman Date: Thu, 4 Mar 2021 14:51:35 +1300 Subject: [PATCH 1/4] always declare write/read of uint64_t in Xdr Signed-off-by: Peter Hillman --- src/lib/OpenEXR/ImfXdr.h | 86 ++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/lib/OpenEXR/ImfXdr.h b/src/lib/OpenEXR/ImfXdr.h index 4e3d8e1dc4..d2473fed5b 100644 --- a/src/lib/OpenEXR/ImfXdr.h +++ b/src/lib/OpenEXR/ImfXdr.h @@ -460,6 +460,28 @@ write (T &out, signed long v) writeSignedChars (out, b, 8); } +template +void +write (T &out, uint64_t v) +{ + unsigned char b[8]; + + b[0] = (unsigned char) (v); + b[1] = (unsigned char) (v >> 8); + b[2] = (unsigned char) (v >> 16); + b[3] = (unsigned char) (v >> 24); + b[4] = (unsigned char) (v >> 32); + b[5] = (unsigned char) (v >> 40); + b[6] = (unsigned char) (v >> 48); + b[7] = (unsigned char) (v >> 56); + + writeUnsignedChars (out, b, 8); +} + + + + +#if ULONG_MAX != 18446744073709551615LU template void @@ -487,7 +509,7 @@ write (T &out, unsigned long v) b[7] = (unsigned char) (v >> 56); #else - + #error write (T &out, unsigned long v) not implemented #endif @@ -495,27 +517,6 @@ write (T &out, unsigned long v) writeUnsignedChars (out, b, 8); } - -#if ULONG_MAX != 18446744073709551615LU - - template - void - write (T &out, uint64_t v) - { - unsigned char b[8]; - - b[0] = (unsigned char) (v); - b[1] = (unsigned char) (v >> 8); - b[2] = (unsigned char) (v >> 16); - b[3] = (unsigned char) (v >> 24); - b[4] = (unsigned char) (v >> 32); - b[5] = (unsigned char) (v >> 40); - b[6] = (unsigned char) (v >> 48); - b[7] = (unsigned char) (v >> 56); - - writeUnsignedChars (out, b, 8); - } - #endif @@ -738,6 +739,26 @@ read (T &in, signed long &v) } +template +void +read (T &in, uint64_t &v) +{ + unsigned char b[8]; + + readUnsignedChars (in, b, 8); + + v = ((uint64_t) b[0] & 0x00000000000000ffLL) | + (((uint64_t) b[1] << 8) & 0x000000000000ff00LL) | + (((uint64_t) b[2] << 16) & 0x0000000000ff0000LL) | + (((uint64_t) b[3] << 24) & 0x00000000ff000000LL) | + (((uint64_t) b[4] << 32) & 0x000000ff00000000LL) | + (((uint64_t) b[5] << 40) & 0x0000ff0000000000LL) | + (((uint64_t) b[6] << 48) & 0x00ff000000000000LL) | + ((uint64_t) b[7] << 56); +} + + +#if ULONG_MAX != 18446744073709551615LU template void read (T &in, unsigned long &v) @@ -777,27 +798,6 @@ read (T &in, unsigned long &v) #endif } - -#if ULONG_MAX != 18446744073709551615LU - - template - void - read (T &in, uint64_t &v) - { - unsigned char b[8]; - - readUnsignedChars (in, b, 8); - - v = ((uint64_t) b[0] & 0x00000000000000ffLL) | - (((uint64_t) b[1] << 8) & 0x000000000000ff00LL) | - (((uint64_t) b[2] << 16) & 0x0000000000ff0000LL) | - (((uint64_t) b[3] << 24) & 0x00000000ff000000LL) | - (((uint64_t) b[4] << 32) & 0x000000ff00000000LL) | - (((uint64_t) b[5] << 40) & 0x0000ff0000000000LL) | - (((uint64_t) b[6] << 48) & 0x00ff000000000000LL) | - ((uint64_t) b[7] << 56); - } - #endif From def952c09c15d2a6c1b0e95396b717339dd54b48 Mon Sep 17 00:00:00 2001 From: Peter Hillman Date: Thu, 4 Mar 2021 15:09:59 +1300 Subject: [PATCH 2/4] fix inconsistency in Xdr declarations Signed-off-by: Peter Hillman --- src/lib/OpenEXR/ImfXdr.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lib/OpenEXR/ImfXdr.h b/src/lib/OpenEXR/ImfXdr.h index d2473fed5b..cf2fd4278d 100644 --- a/src/lib/OpenEXR/ImfXdr.h +++ b/src/lib/OpenEXR/ImfXdr.h @@ -157,14 +157,12 @@ write (T &out, signed long v); template void -write (T &out, unsigned long v); +write (T &out, uint64_t v); #if ULONG_MAX != 18446744073709551615LU - template void - write (T &out, uint64_t v); - + write (T &out, unsigned long v); #endif template @@ -240,13 +238,14 @@ read (T &in, signed long &v); template void -read (T &in, unsigned long &v); +read (T &in, uint64_t &v); + #if ULONG_MAX != 18446744073709551615LU template void - read (T &in, uint64_t &v); + read (T &in, unsigned long &v); #endif From a395ac451072e3dc902fe926633d326534fa486d Mon Sep 17 00:00:00 2001 From: Peter Hillman Date: Thu, 4 Mar 2021 15:10:58 +1300 Subject: [PATCH 3/4] CompressedIDManifest size field is uint64_t not size_t Signed-off-by: Peter Hillman --- src/lib/OpenEXR/ImfIDManifestAttribute.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lib/OpenEXR/ImfIDManifestAttribute.cpp b/src/lib/OpenEXR/ImfIDManifestAttribute.cpp index 6403234cf9..3f2641c517 100644 --- a/src/lib/OpenEXR/ImfIDManifestAttribute.cpp +++ b/src/lib/OpenEXR/ImfIDManifestAttribute.cpp @@ -22,7 +22,8 @@ template <> void IDManifestAttribute::writeValueTo (OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, int version) const { - Xdr::write(os,_value._uncompressedDataSize); + uint64_t uncompressedDataSize = _value._uncompressedDataSize; + Xdr::write(os,uncompressedDataSize); const char* output = (const char*) _value._data; Xdr::write (os, output,_value._compressedDataSize); @@ -47,11 +48,13 @@ IDManifestAttribute::readValueFrom (OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, _value._data = nullptr; } - + uint64_t uncompressedDataSize; // - // first four bytes: data size once data is uncompressed + // first eight bytes: data size once data is uncompressed // - Xdr::read(is,_value._uncompressedDataSize); + Xdr::read(is,uncompressedDataSize); + + _value._uncompressedDataSize = uncompressedDataSize; // // allocate memory for compressed storage and read data From 96becca4d77df93107251143bd53088640bc4455 Mon Sep 17 00:00:00 2001 From: Peter Hillman Date: Thu, 4 Mar 2021 15:42:16 +1300 Subject: [PATCH 4/4] remove 'long' overloads from Xdr read/write Signed-off-by: Peter Hillman --- src/lib/OpenEXR/ImfXdr.h | 175 +++---------------------------- src/test/OpenEXRTest/testXdr.cpp | 16 +-- 2 files changed, 24 insertions(+), 167 deletions(-) diff --git a/src/lib/OpenEXR/ImfXdr.h b/src/lib/OpenEXR/ImfXdr.h index cf2fd4278d..0ebe807c44 100644 --- a/src/lib/OpenEXR/ImfXdr.h +++ b/src/lib/OpenEXR/ImfXdr.h @@ -153,17 +153,12 @@ write (T &out, unsigned int v); template void -write (T &out, signed long v); +write (T &out, int64_t v); template void write (T &out, uint64_t v); -#if ULONG_MAX != 18446744073709551615LU - template - void - write (T &out, unsigned long v); -#endif template void @@ -234,21 +229,12 @@ read (T &in, unsigned int &v); template void -read (T &in, signed long &v); +read (T &in, int64_t &v); template void read (T &in, uint64_t &v); - -#if ULONG_MAX != 18446744073709551615LU - - template - void - read (T &in, unsigned long &v); - -#endif - template void read (T &in, float &v); @@ -417,7 +403,7 @@ write (T &out, unsigned int v) template void -write (T &out, signed long v) +write (T &out, int64_t v) { signed char b[8]; @@ -425,36 +411,10 @@ write (T &out, signed long v) b[1] = (signed char) (v >> 8); b[2] = (signed char) (v >> 16); b[3] = (signed char) (v >> 24); - - #if LONG_MAX == 2147483647 - - if (v >= 0) - { - b[4] = 0; - b[5] = 0; - b[6] = 0; - b[7] = 0; - } - else - { - b[4] = ~0; - b[5] = ~0; - b[6] = ~0; - b[7] = ~0; - } - - #elif LONG_MAX == 9223372036854775807L - - b[4] = (signed char) (v >> 32); - b[5] = (signed char) (v >> 40); - b[6] = (signed char) (v >> 48); - b[7] = (signed char) (v >> 56); - - #else - - #error write (T &out, signed long v) not implemented - - #endif + b[4] = (signed char) (v >> 32); + b[5] = (signed char) (v >> 40); + b[6] = (signed char) (v >> 48); + b[7] = (signed char) (v >> 56); writeSignedChars (out, b, 8); } @@ -480,45 +440,6 @@ write (T &out, uint64_t v) -#if ULONG_MAX != 18446744073709551615LU - -template -void -write (T &out, unsigned long v) -{ - unsigned char b[8]; - - b[0] = (unsigned char) (v); - b[1] = (unsigned char) (v >> 8); - b[2] = (unsigned char) (v >> 16); - b[3] = (unsigned char) (v >> 24); - - #if ULONG_MAX == 4294967295U - - b[4] = 0; - b[5] = 0; - b[6] = 0; - b[7] = 0; - - #elif ULONG_MAX == 18446744073709551615LU - - b[4] = (unsigned char) (v >> 32); - b[5] = (unsigned char) (v >> 40); - b[6] = (unsigned char) (v >> 48); - b[7] = (unsigned char) (v >> 56); - - #else - - #error write (T &out, unsigned long v) not implemented - - #endif - - writeUnsignedChars (out, b, 8); -} - -#endif - - template void write (T &out, float v) @@ -699,42 +620,21 @@ read (T &in, unsigned int &v) template void -read (T &in, signed long &v) +read (T &in, int64_t &v) { signed char b[8]; readSignedChars (in, b, 8); - #if LONG_MAX == 2147483647 - - v = (static_cast (b[0]) & 0x000000ff) | - ((static_cast (b[1]) << 8) & 0x0000ff00) | - ((static_cast (b[2]) << 16) & 0x00ff0000) | - (static_cast (b[3]) << 24); - - if (( b[4] || b[5] || b[6] || b[7]) && - (~b[4] || ~b[5] || ~b[6] || ~b[7])) - { - throw IEX_NAMESPACE::OverflowExc ("Long int overflow - read a large " - "64-bit integer in a 32-bit process."); - } - - #elif LONG_MAX == 9223372036854775807L + v = (static_cast (b[0]) & 0x00000000000000ff) | + ((static_cast (b[1]) << 8) & 0x000000000000ff00) | + ((static_cast (b[2]) << 16) & 0x0000000000ff0000) | + ((static_cast (b[3]) << 24) & 0x00000000ff000000) | + ((static_cast (b[4]) << 32) & 0x000000ff00000000) | + ((static_cast (b[5]) << 40) & 0x0000ff0000000000) | + ((static_cast (b[6]) << 48) & 0x00ff000000000000) | + (static_cast (b[7]) << 56); - v = (static_cast (b[0]) & 0x00000000000000ff) | - ((static_cast (b[1]) << 8) & 0x000000000000ff00) | - ((static_cast (b[2]) << 16) & 0x0000000000ff0000) | - ((static_cast (b[3]) << 24) & 0x00000000ff000000) | - ((static_cast (b[4]) << 32) & 0x000000ff00000000) | - ((static_cast (b[5]) << 40) & 0x0000ff0000000000) | - ((static_cast (b[6]) << 48) & 0x00ff000000000000) | - (static_cast (b[7]) << 56); - - #else - - #error read (T &in, signed long &v) not implemented - - #endif } @@ -757,49 +657,6 @@ read (T &in, uint64_t &v) } -#if ULONG_MAX != 18446744073709551615LU -template -void -read (T &in, unsigned long &v) -{ - unsigned char b[8]; - - readUnsignedChars (in, b, 8); - - #if ULONG_MAX == 4294967295U - - v = (b[0] & 0x000000ff) | - ((b[1] << 8) & 0x0000ff00) | - ((b[2] << 16) & 0x00ff0000) | - (b[3] << 24); - - if (b[4] || b[5] || b[6] || b[7]) - { - throw IEX_NAMESPACE::OverflowExc ("Long int overflow - read a large " - "64-bit integer in a 32-bit process."); - } - - #elif ULONG_MAX == 18446744073709551615LU - - v = ((unsigned long) b[0] & 0x00000000000000ff) | - (((unsigned long) b[1] << 8) & 0x000000000000ff00) | - (((unsigned long) b[2] << 16) & 0x0000000000ff0000) | - (((unsigned long) b[3] << 24) & 0x00000000ff000000) | - (((unsigned long) b[4] << 32) & 0x000000ff00000000) | - (((unsigned long) b[5] << 40) & 0x0000ff0000000000) | - (((unsigned long) b[6] << 48) & 0x00ff000000000000) | - ((unsigned long) b[7] << 56); - - #else - - #error read (T &in, unsigned long &v) not implemented - - #endif -} - -#endif - - template void read (T &in, float &v) diff --git a/src/test/OpenEXRTest/testXdr.cpp b/src/test/OpenEXRTest/testXdr.cpp index 95033bd58b..34d78b106e 100644 --- a/src/test/OpenEXRTest/testXdr.cpp +++ b/src/test/OpenEXRTest/testXdr.cpp @@ -92,10 +92,10 @@ writeData (ostream &os) Xdr::write (os, (signed int) -2012345678); Xdr::write (os, (unsigned int) 1234567890u); Xdr::write (os, (unsigned int) 2345678901u); - Xdr::write (os, (signed long) 2034567890); - Xdr::write (os, (signed long) -2045678901); - Xdr::write (os, (unsigned long) 1345678901u); - Xdr::write (os, (unsigned long) 2456789012u); + Xdr::write (os, (int64_t) 2034567890); + Xdr::write (os, (int64_t) -2045678901); + Xdr::write (os, (uint64_t) 1345678901u); + Xdr::write (os, (uint64_t) 2456789012u); Xdr::write (os, (uint64_t) 0x1122334455667788ll); Xdr::write (os, (uint64_t) 0xf1f2f3f4f5f6f7f8ll); Xdr::write (os, (float) 0.0f); @@ -195,10 +195,10 @@ readData (istream &is) check (is, (signed int) -2012345678); check (is, (unsigned int) 1234567890u); check (is, (unsigned int) 2345678901u); - check (is, (signed long) 2034567890); - check (is, (signed long) -2045678901); - check (is, (unsigned long) 1345678901u); - check (is, (unsigned long) 2456789012u); + check (is, (int64_t) 2034567890); + check (is, (int64_t) -2045678901); + check (is, (uint64_t) 1345678901u); + check (is, (uint64_t) 2456789012u); check (is, (uint64_t) 0x1122334455667788ll); check (is, (uint64_t) 0xf1f2f3f4f5f6f7f8ll); check (is, (float) 0.0f);