From b2a9646be9c3441a908a8060ad1e5b7cdab0dafe Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 7 Feb 2022 14:24:41 -0800 Subject: [PATCH] QIODevice::readAll: allow reading from a huge non-sequential devices On 32-bit systems, the non-sequential device could be pointing to a device of 2 GB or more in size. If so, we should allow reading up to the limit (2 GB - overhead), like we do for sequential devices in the block above. It could also happen on 64-bit systems, but the chance that you do have a file bigger than 8 EB is remote. [ChangeLog][QtCore][QIODevice] Changed readAll() handling of large non-sequential devices like files that are bigger than the maximum QByteArray size (on 32-bit systems, just under 2 GB). Previously, readAll() always returned empty; now it will attempt to read from the device. Task-number: QTBUG-100546 Pick-to: 6.3 Change-Id: I74249c52dc02478ba93cfffd16d1a14ac92c77bb Reviewed-by: Marc Mutz Reviewed-by: Oswald Buddenhagen --- src/corelib/io/qiodevice.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index bd1eaf11ce..978c6f2486 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -1261,7 +1261,9 @@ QByteArray QIODevice::read(qint64 maxSize) This function has no way of reporting errors; returning an empty QByteArray can mean either that no data was currently available - for reading, or that an error occurred. + for reading, or that an error occurred. This function also has no + way of indicating that more data may have been available and + couldn't be read. */ QByteArray QIODevice::readAll() { @@ -1295,10 +1297,9 @@ QByteArray QIODevice::readAll() } while (readResult > 0); } else { // Read it all in one go. - // If resize fails, don't read anything. readBytes -= d->pos; if (readBytes >= MaxByteArraySize) - return QByteArray(); + readBytes = MaxByteArraySize; result.resize(readBytes); readBytes = d->read(result.data(), readBytes); }