Skip to content

Commit

Permalink
std/file: use size_t instead of ulong for ReadFile on Windows
Browse files Browse the repository at this point in the history
Since ReadFile requires an offset buffer and the maximum size is size_t.max, we
should offset with size_t to avoid overflow on dereferencing.

Signed-off-by: Luís Ferreira <contact@lsferreira.net>
  • Loading branch information
ljmf00 authored and dlang-bot committed Feb 27, 2022
1 parent 2de6834 commit 5bc8b25
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions std/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,10 @@ version (Windows) private void[] readImpl(scope const(char)[] name, scope const(
fileSize = makeUlong(sizeLow, sizeHigh);
return result;
}
static trustedReadFile(HANDLE hFile, void *lpBuffer, ulong nNumberOfBytesToRead)
static trustedReadFile(HANDLE hFile, void *lpBuffer, size_t nNumberOfBytesToRead)
{
// Read by chunks of size < 4GB (Windows API limit)
ulong totalNumRead = 0;
size_t totalNumRead = 0;
while (totalNumRead != nNumberOfBytesToRead)
{
const uint chunkSize = min(nNumberOfBytesToRead - totalNumRead, 0xffff_0000);
Expand Down

0 comments on commit 5bc8b25

Please sign in to comment.