summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-02-07 14:24:41 -0800
committerThiago Macieira <thiago.macieira@intel.com>2022-02-17 17:02:18 -0800
commitb2a9646be9c3441a908a8060ad1e5b7cdab0dafe (patch)
treecdd3b017c511bf653695e80d1ab3ca01de2d4756
parente4fe301a77dae846e707b6e2761173eaccf9d650 (diff)
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 <marc.mutz@qt.io> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
-rw-r--r--src/corelib/io/qiodevice.cpp7
1 files 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);
}