[docs] qCompress/qUncompress: document size limits

Zlib uses ulong in the interface, which, at least on Windows, is a
32-bit type, so qCompress cannot consume input and qUncompress cannot
produce output greater than ULONG_MAX, even on 64-bit platforms.

Document this limitation.

Task-number: QTBUG-104972
Change-Id: I56c926a67f8705ef773977a86e157e6eb26aa585
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 6bdde5295708df78db45c120d123945447f00232)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2022-09-06 22:02:47 +02:00 committed by Qt Cherry-pick Bot
parent cab293de79
commit 64b53da19a

View File

@ -505,6 +505,15 @@ quint16 qChecksum(QByteArrayView data, Qt::ChecksumType standard)
The default value is -1, which specifies zlib's default The default value is -1, which specifies zlib's default
compression. compression.
//![compress-limit-note]
\note The maximum size of data that this function can consume is limited by
what the platform's \c{unsigned long} can represent (a Zlib limitation).
That means that data > 4GiB can be compressed and decompressed on a 64-bit
Unix system, but not on a 64-bit Windows system. Portable code should
therefore avoid using qCompress()/qUncompress() to compress more than 4GiB
of input.
//![compress-limit-note]
\sa qUncompress(const QByteArray &data) \sa qUncompress(const QByteArray &data)
*/ */
@ -514,6 +523,8 @@ quint16 qChecksum(QByteArrayView data, Qt::ChecksumType standard)
Compresses the first \a nbytes of \a data at compression level Compresses the first \a nbytes of \a data at compression level
\a compressionLevel and returns the compressed data in a new byte array. \a compressionLevel and returns the compressed data in a new byte array.
\include qbytearray.cpp compress-limit-note
*/ */
#ifndef QT_NO_COMPRESS #ifndef QT_NO_COMPRESS
@ -578,6 +589,15 @@ QByteArray qCompress(const uchar* data, qsizetype nbytes, int compressionLevel)
contain the expected length (in bytes) of the uncompressed data, contain the expected length (in bytes) of the uncompressed data,
expressed as an unsigned, big-endian, 32-bit integer. expressed as an unsigned, big-endian, 32-bit integer.
//![uncompress-limit-note]
\note The maximum size of data that this function can produce is limited by
what the platform's \c{unsigned long} can represent (a Zlib limitation).
That means that data > 4GiB can be compressed and decompressed on a 64-bit
Unix system, but not on a 64-bit Windows system. Portable code should
therefore avoid using qCompress()/qUncompress() to compress more than 4GiB
of input.
//![uncompress-limit-note]
\sa qCompress() \sa qCompress()
*/ */
@ -594,6 +614,8 @@ static QByteArray invalidCompressedData()
Uncompresses the first \a nbytes of \a data and returns a new byte Uncompresses the first \a nbytes of \a data and returns a new byte
array with the uncompressed data. array with the uncompressed data.
\include qbytearray.cpp uncompress-limit-note
*/ */
QByteArray qUncompress(const uchar* data, qsizetype nbytes) QByteArray qUncompress(const uchar* data, qsizetype nbytes)
{ {