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>
This commit is contained in:
Thiago Macieira 2022-02-07 14:24:41 -08:00
parent e4fe301a77
commit b2a9646be9

View File

@ -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);
}