Windows: Fix truncation in QFSFileEnginePrivate::nativeWrite()

The number of bytes to write was converted to a 32bit unsigned value,
causing losses. Change the type to qint64 and adapt the code determining
the block size.

Task-number: QTBUG-54870
Change-Id: I294da5bfe97c7e60f67228399e1244a1aba4c89c
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
This commit is contained in:
Friedemann Kleint 2016-07-20 16:49:33 +02:00
parent 1ef8c640f8
commit 0696566b1e

View File

@ -423,15 +423,13 @@ qint64 QFSFileEnginePrivate::nativeWrite(const char *data, qint64 len)
if (fileHandle == INVALID_HANDLE_VALUE)
return -1;
qint64 bytesToWrite = DWORD(len); // <- lossy
qint64 bytesToWrite = len;
// Writing 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;
const DWORD blockSize = DWORD(qMin(bytesToWrite, qint64(32 * 1024 * 1024)));
qint64 totalWritten = 0;
do {
DWORD blockSize = qMin<DWORD>(bytesToWrite, maxBlockSize);
DWORD bytesWritten;
if (!WriteFile(fileHandle, data + totalWritten, blockSize, &bytesWritten, NULL)) {
if (totalWritten == 0) {