diff options
author | Øystein Heskestad <oystein.heskestad@qt.io> | 2023-10-04 13:59:06 +0200 |
---|---|---|
committer | Øystein Heskestad <oystein.heskestad@qt.io> | 2023-10-23 15:10:28 +0200 |
commit | fd48ce0b73c74dafd5db27bc1f2752ef665df7ef (patch) | |
tree | 086f986f7befe9a0cb40f88f04c28a0c07293939 /src/corelib/text/qbytearray.cpp | |
parent | 0d413506a1b019efecff41318a9134d79f2abcd1 (diff) |
Add support for containers > 4 Gi elements in QDataStream
The format is changed from 6.7 to support more than UINT32_MAX - 1
elements. The format used to have a quint32 size. Now if the size is
larger or equal to 0xfffffffe (2^32 -2) the old size is an extend
value 0xfffffffe followed by one quint64 with the actual value. The
32 bit size with all bits set is still used as null value.
Fixes: QTBUG-105034
Change-Id: I62188be170fe779022ad58ab84a54b1eaf46e5d9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/text/qbytearray.cpp')
-rw-r--r-- | src/corelib/text/qbytearray.cpp | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/corelib/text/qbytearray.cpp b/src/corelib/text/qbytearray.cpp index b0e3590e28..193d093c0d 100644 --- a/src/corelib/text/qbytearray.cpp +++ b/src/corelib/text/qbytearray.cpp @@ -3266,7 +3266,7 @@ void QByteArray::clear() QDataStream &operator<<(QDataStream &out, const QByteArray &ba) { if (ba.isNull() && out.version() >= 6) { - out << (quint32)0xffffffff; + QDataStream::writeQSizeType(out, -1); return out; } return out.writeBytes(ba.constData(), ba.size()); @@ -3283,15 +3283,21 @@ QDataStream &operator<<(QDataStream &out, const QByteArray &ba) QDataStream &operator>>(QDataStream &in, QByteArray &ba) { ba.clear(); - quint32 len; - in >> len; - if (len == 0xffffffff) { // null byte-array + + qint64 size = QDataStream::readQSizeType(in); + qsizetype len = size; + if (size != len || size < -1) { + ba.clear(); + in.setStatus(QDataStream::ReadCorruptData); + return in; + } + if (len == -1) { // null byte-array ba = QByteArray(); return in; } - const quint32 Step = 1024 * 1024; - quint32 allocated = 0; + constexpr qsizetype Step = 1024 * 1024; + qsizetype allocated = 0; do { qsizetype blockSize = qMin(Step, len - allocated); |