From 64b53da19af2e82ef965b83c43e1c53c57fee0bd Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 6 Sep 2022 22:02:47 +0200 Subject: [PATCH] [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 (cherry picked from commit 6bdde5295708df78db45c120d123945447f00232) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/text/qbytearray.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index aac2738317a..b517f62e56e 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -505,6 +505,15 @@ quint16 qChecksum(QByteArrayView data, Qt::ChecksumType standard) The default value is -1, which specifies zlib's default 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) */ @@ -514,6 +523,8 @@ quint16 qChecksum(QByteArrayView data, Qt::ChecksumType standard) Compresses the first \a nbytes of \a data at compression level \a compressionLevel and returns the compressed data in a new byte array. + + \include qbytearray.cpp compress-limit-note */ #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, 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() */ @@ -594,6 +614,8 @@ static QByteArray invalidCompressedData() Uncompresses the first \a nbytes of \a data and returns a new byte array with the uncompressed data. + + \include qbytearray.cpp uncompress-limit-note */ QByteArray qUncompress(const uchar* data, qsizetype nbytes) {