diff OrthancFramework/Sources/Compression/ZlibCompressor.cpp @ 4455:a8f554ca5ac6

Explicitly use little-endian to encode uncompressed file size with zlib compression
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 19 Jan 2021 14:31:04 +0100
parents d9473bd5ed43
children 0b2484663233
line wrap: on
line diff
--- a/OrthancFramework/Sources/Compression/ZlibCompressor.cpp	Tue Jan 19 12:03:49 2021 +0100
+++ b/OrthancFramework/Sources/Compression/ZlibCompressor.cpp	Tue Jan 19 14:31:04 2021 +0100
@@ -23,6 +23,7 @@
 #include "../PrecompiledHeaders.h"
 #include "ZlibCompressor.h"
 
+#include "../Endianness.h"
 #include "../OrthancException.h"
 #include "../Logging.h"
 
@@ -90,6 +91,10 @@
     if (HasPrefixWithUncompressedSize())
     {
       uint64_t s = static_cast<uint64_t>(uncompressedSize);
+
+      // New in Orthanc 1.9.0: Explicitly use litte-endian encoding in size prefix
+      s = htole64(s);
+
       memcpy(&compressed[0], &s, sizeof(uint64_t));
       compressed.resize(compressedSize + sizeof(uint64_t));
     }
@@ -127,6 +132,9 @@
       throw OrthancException(ErrorCode_NotEnoughMemory);
     }
 
+    // New in Orthanc 1.9.0: Explicitly use litte-endian encoding in size prefix
+    uncompressedSize = le64toh(uncompressedSize);
+
     uLongf tmp = static_cast<uLongf>(uncompressedSize);
     int error = uncompress
       (reinterpret_cast<uint8_t*>(&uncompressed[0]),