diff --git a/src/port/win32pread.c b/src/port/win32pread.c index e1a066fdbe..2d022e6d37 100644 --- a/src/port/win32pread.c +++ b/src/port/win32pread.c @@ -30,6 +30,9 @@ pg_pread(int fd, void *buf, size_t size, off_t offset) return -1; } + /* Avoid overflowing DWORD. */ + size = Min(size, 1024 * 1024 * 1024); + /* Note that this changes the file position, despite not using it. */ overlapped.Offset = offset; if (!ReadFile(handle, buf, size, &result, &overlapped)) diff --git a/src/port/win32pwrite.c b/src/port/win32pwrite.c index c54bf041bf..b37bb2f92e 100644 --- a/src/port/win32pwrite.c +++ b/src/port/win32pwrite.c @@ -30,6 +30,9 @@ pg_pwrite(int fd, const void *buf, size_t size, off_t offset) return -1; } + /* Avoid overflowing DWORD. */ + size = Min(size, 1024 * 1024 * 1024); + /* Note that this changes the file position, despite not using it. */ overlapped.Offset = offset; if (!WriteFile(handle, buf, size, &result, &overlapped))