Fix nativeRead() for maxlen greater than UINT_MAX

Don't truncate the maxlen to a DWORD. Instead read all
data incrementally up t maxlen.

Task-number: QTBUG-27796

Change-Id: I21c34d11046f1106244dcd77420cc472e7240e68
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Lars Knoll 2014-08-26 13:03:59 +02:00
parent fc4993be1f
commit 1d66c9eba8

View File

@ -369,15 +369,15 @@ qint64 QFSFileEnginePrivate::nativeRead(char *data, qint64 maxlen)
if (fileHandle == INVALID_HANDLE_VALUE)
return -1;
DWORD bytesToRead = DWORD(maxlen); // <- lossy
qint64 bytesToRead = maxlen;
// Reading on Windows fails with ERROR_NO_SYSTEM_RESOURCES when
// the chunks are too large, so we limit the block size to 32MB.
static const DWORD maxBlockSize = 32 * 1024 * 1024;
static const qint64 maxBlockSize = 32 * 1024 * 1024;
qint64 totalRead = 0;
do {
DWORD blockSize = qMin<DWORD>(bytesToRead, maxBlockSize);
DWORD blockSize = DWORD(qMin(bytesToRead, maxBlockSize));
DWORD bytesRead;
if (!ReadFile(fileHandle, data + totalRead, blockSize, &bytesRead, NULL)) {
if (totalRead == 0) {
@ -392,7 +392,7 @@ qint64 QFSFileEnginePrivate::nativeRead(char *data, qint64 maxlen)
totalRead += bytesRead;
bytesToRead -= bytesRead;
} while (totalRead < maxlen);
return qint64(totalRead);
return totalRead;
}
/*