From 1d66c9eba81ea8b73f354984e9eca2beda089faf Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 26 Aug 2014 13:03:59 +0200 Subject: 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 --- src/corelib/io/qfsfileengine_win.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/corelib') diff --git a/src/corelib/io/qfsfileengine_win.cpp b/src/corelib/io/qfsfileengine_win.cpp index 81aed5f7b4..cebca1a56f 100644 --- a/src/corelib/io/qfsfileengine_win.cpp +++ b/src/corelib/io/qfsfileengine_win.cpp @@ -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(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; } /* -- cgit v1.2.3