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
This commit is contained in:
Thomas Munro 2024-03-03 08:40:41 +13:00
parent 653b55b570
commit 1e01374654
2 changed files with 6 additions and 0 deletions

View File

@ -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))

View File

@ -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))