comparison 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
comparison
equal deleted inserted replaced
4454:f20a7655fb1c 4455:a8f554ca5ac6
21 21
22 22
23 #include "../PrecompiledHeaders.h" 23 #include "../PrecompiledHeaders.h"
24 #include "ZlibCompressor.h" 24 #include "ZlibCompressor.h"
25 25
26 #include "../Endianness.h"
26 #include "../OrthancException.h" 27 #include "../OrthancException.h"
27 #include "../Logging.h" 28 #include "../Logging.h"
28 29
29 #include <stdio.h> 30 #include <stdio.h>
30 #include <string.h> 31 #include <string.h>
88 89
89 // The compression was successful 90 // The compression was successful
90 if (HasPrefixWithUncompressedSize()) 91 if (HasPrefixWithUncompressedSize())
91 { 92 {
92 uint64_t s = static_cast<uint64_t>(uncompressedSize); 93 uint64_t s = static_cast<uint64_t>(uncompressedSize);
94
95 // New in Orthanc 1.9.0: Explicitly use litte-endian encoding in size prefix
96 s = htole64(s);
97
93 memcpy(&compressed[0], &s, sizeof(uint64_t)); 98 memcpy(&compressed[0], &s, sizeof(uint64_t));
94 compressed.resize(compressedSize + sizeof(uint64_t)); 99 compressed.resize(compressedSize + sizeof(uint64_t));
95 } 100 }
96 else 101 else
97 { 102 {
125 catch (...) 130 catch (...)
126 { 131 {
127 throw OrthancException(ErrorCode_NotEnoughMemory); 132 throw OrthancException(ErrorCode_NotEnoughMemory);
128 } 133 }
129 134
135 // New in Orthanc 1.9.0: Explicitly use litte-endian encoding in size prefix
136 uncompressedSize = le64toh(uncompressedSize);
137
130 uLongf tmp = static_cast<uLongf>(uncompressedSize); 138 uLongf tmp = static_cast<uLongf>(uncompressedSize);
131 int error = uncompress 139 int error = uncompress
132 (reinterpret_cast<uint8_t*>(&uncompressed[0]), 140 (reinterpret_cast<uint8_t*>(&uncompressed[0]),
133 &tmp, 141 &tmp,
134 reinterpret_cast<const uint8_t*>(compressed) + sizeof(uint64_t), 142 reinterpret_cast<const uint8_t*>(compressed) + sizeof(uint64_t),