From 8f1a827d91da79f30cc8bb34fe4651b9523b51ab Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 7 Feb 2022 14:13:16 -0800 Subject: [PATCH] QIODevice::read: don't truncate to int(readBytes) QByteArray in Qt 6 *can* hold more than 2GB-overhead of data. Untestable. Fixes: QTBUG-100546 Pick-to: 6.2 6.3 Change-Id: I74249c52dc02478ba93cfffd16d1a0ab398efe9c Reviewed-by: Marc Mutz --- src/corelib/io/qiodevice.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index 57d26884ee..bd1eaf11ce 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -1244,13 +1244,13 @@ QByteArray QIODevice::read(qint64 maxSize) CHECK_MAXLEN(read, result); CHECK_MAXBYTEARRAYSIZE(read); - result.resize(int(maxSize)); + result.resize(qsizetype(maxSize)); qint64 readBytes = d->read(result.data(), result.size()); if (readBytes <= 0) result.clear(); else - result.resize(int(readBytes)); + result.resize(qsizetype(readBytes)); return result; } @@ -1306,7 +1306,7 @@ QByteArray QIODevice::readAll() if (readBytes <= 0) result.clear(); else - result.resize(int(readBytes)); + result.resize(qsizetype(readBytes)); return result; } @@ -1367,7 +1367,7 @@ qint64 QIODevice::readLine(char *data, qint64 maxSize) #if defined QIODEVICE_DEBUG printf("%p \treturning %lld, d->pos = %lld, d->buffer.size() = %lld, size() = %lld\n", this, readBytes, d->pos, d->buffer.size(), size()); - debugBinaryString(data, int(readBytes)); + debugBinaryString(data, qsizetype(readBytes)); #endif return readBytes; @@ -1411,7 +1411,7 @@ qint64 QIODevicePrivate::readLine(char *data, qint64 maxSize) #if defined QIODEVICE_DEBUG printf("%p \tread from buffer: %lld bytes, last character read: %hhx\n", q, readSoFar, data[readSoFar - 1]); - debugBinaryString(data, int(readSoFar)); + debugBinaryString(data, qsizetype(readSoFar)); #endif if (data[readSoFar - 1] == '\n') { if (openMode & QIODevice::Text) { @@ -1438,7 +1438,7 @@ qint64 QIODevicePrivate::readLine(char *data, qint64 maxSize) printf("%p \tread from readLineData: %lld bytes, readSoFar = %lld bytes\n", q, readBytes, readSoFar); if (readBytes > 0) { - debugBinaryString(data, int(readSoFar + readBytes)); + debugBinaryString(data, qsizetype(readSoFar + readBytes)); } #endif if (readBytes < 0) { @@ -1496,12 +1496,12 @@ QByteArray QIODevice::readLine(qint64 maxSize) qint64 readResult; do { - result.resize(int(qMin(maxSize, qint64(result.size() + d->buffer.chunkSize())))); + result.resize(qsizetype(qMin(maxSize, qint64(result.size() + d->buffer.chunkSize())))); readResult = d->readLine(result.data() + readBytes, result.size() - readBytes); if (readResult > 0 || readBytes == 0) readBytes += readResult; } while (readResult == d->buffer.chunkSize() - && result[int(readBytes - 1)] != '\n'); + && result[qsizetype(readBytes - 1)] != '\n'); } else { CHECK_LINEMAXLEN(readLine, result); CHECK_MAXBYTEARRAYSIZE(readLine);