Skip to content

Commit 1e01374

Browse files
committed
Fix overflow in Windows replacement pg_pread/pg_pwrite.
When calling the Windows file I/O APIs there is an implicit conversion from size_t to DWORD, which could overflow. Clamp the size at 1GB to avoid that. Not a really a live bug as we don't expect anything in PostgreSQL to call with such large values. Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Discussion: https://postgr.es/m/1672202.1703441340%40sss.pgh.pa.us
1 parent 653b55b commit 1e01374

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/port/win32pread.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ pg_pread(int fd, void *buf, size_t size, off_t offset)
3030
return -1;
3131
}
3232

33+
/* Avoid overflowing DWORD. */
34+
size = Min(size, 1024 * 1024 * 1024);
35+
3336
/* Note that this changes the file position, despite not using it. */
3437
overlapped.Offset = offset;
3538
if (!ReadFile(handle, buf, size, &result, &overlapped))

src/port/win32pwrite.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ pg_pwrite(int fd, const void *buf, size_t size, off_t offset)
3030
return -1;
3131
}
3232

33+
/* Avoid overflowing DWORD. */
34+
size = Min(size, 1024 * 1024 * 1024);
35+
3336
/* Note that this changes the file position, despite not using it. */
3437
overlapped.Offset = offset;
3538
if (!WriteFile(handle, buf, size, &result, &overlapped))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy