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 <[email protected]>
Discussion: https://postgr.es/m/
1672202.
1703441340%40sss.pgh.pa.us
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))
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))