qUncompress: limit MaxDecompressedSize to what zlib can handle

... which may be less than what QByteArray can handle, e.g. on Windows,
where long, used in the zlib API as the size type, is just 32-bit.

Re-define MaxDecompressedSize as the minimum of the maximum sizes
supported by each of QByteArray and zlib, so we respect each library's
individual limit.

Pick-to: 6.4 6.3 6.2
Task-number: QTBUG-104972
Change-Id: If1894ae7a1888f651a82b153d463658c272287e3
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
bb10
Marc Mutz 2022-09-06 21:36:48 +02:00 committed by Thiago Macieira
parent 6ed89be125
commit f3512ada09
1 changed files with 2 additions and 1 deletions

View File

@ -632,7 +632,8 @@ QByteArray qUncompress(const uchar* data, qsizetype nbytes)
size_t expectedSize = size_t((data[0] << 24) | (data[1] << 16) |
(data[2] << 8) | (data[3] ));
size_t len = qMax(expectedSize, 1ul);
constexpr size_t MaxDecompressedSize = size_t(MaxByteArraySize);
constexpr size_t MaxZLibSize = (std::numeric_limits<uLong>::max)();
constexpr size_t MaxDecompressedSize = (std::min)(size_t(MaxByteArraySize), MaxZLibSize);
if (len > MaxDecompressedSize)
return invalidCompressedData();