diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2015-03-28 15:03:18 +0200 |
---|---|---|
committer | Alex Trotsenko <alex1973tr@gmail.com> | 2015-04-08 16:35:40 +0000 |
commit | 7c149dd86944b3669420832b2b14fac00327d4b7 (patch) | |
tree | 0740b644542a31d79fe1efbb76ad49d4727cfb97 /src/corelib/io | |
parent | db52d55fba61abf295de9f8430f60890cde58ee7 (diff) |
Prevent memory overgrowth while reading from a sequential device
After flushing the internal buffer, QIODevice::readAll() attempts
to read the device incrementally. On each iteration, the result buffer
size is increased by a constant value independently from the number of
read bytes. This lead to unreasonable growth of the buffer if these
additional conditions were met:
- readData() requests new data from the device on every call;
- highly loaded device provides at least one byte on each request.
Instead of constant resizing, keep the size of free block to avoid a
possible memory exhaustion.
Task-number: QTBUG-44286
Change-Id: I637e2d0e05bd900a1bb9517af2fe7d8038c75a35
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qiodevice.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/corelib/io/qiodevice.cpp b/src/corelib/io/qiodevice.cpp index 7a87a78c60..43ad8d9316 100644 --- a/src/corelib/io/qiodevice.cpp +++ b/src/corelib/io/qiodevice.cpp @@ -989,8 +989,8 @@ QByteArray QIODevice::readAll() // Size is unknown, read incrementally. qint64 readResult; do { - result.resize(result.size() + QIODEVICE_BUFFERSIZE); - readResult = read(result.data() + readBytes, result.size() - readBytes); + result.resize(readBytes + QIODEVICE_BUFFERSIZE); + readResult = read(result.data() + readBytes, QIODEVICE_BUFFERSIZE); if (readResult > 0 || readBytes == 0) readBytes += readResult; } while (readResult > 0); |