Content-Length: 285373 | pFad | http://github.com/postgrespro/postgres/commit/1e013746544bd1f9df70f5547894fd72719c4b85

02 Fix overflow in Windows replacement pg_pread/pg_pwrite. · postgrespro/postgres@1e01374 · GitHub
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)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgrespro/postgres/commit/1e013746544bd1f9df70f5547894fd72719c4b85

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy