Skip to content

clamp read and write length to INT_MAX in win32 posix shims - #1371

Open
sage-mode-hunter wants to merge 1 commit into
libressl:masterfrom
sage-mode-hunter:win32-io-length-clamp
Open

clamp read and write length to INT_MAX in win32 posix shims#1371
sage-mode-hunter wants to merge 1 commit into
libressl:masterfrom
sage-mode-hunter:win32-io-length-clamp

Conversation

@sage-mode-hunter

Copy link
Copy Markdown
Contributor

posix_read/posix_write are the process-wide read()/write() on Windows (win32netcompat.h maps read/write to them) and pass their size_t count straight into the int-length socket and CRT calls:

  • recv/send take an int length, so a count at or past 2 GiB is narrowed at the call
  • count == 4 GiB truncates to 0, so recv() returns 0 and the read loop reads it as a clean EOF
  • 2 GiB truncates to INT_MIN and fails a valid buffer with WSAEFAULT; 4 GiB + 1024 sends 1024 and reports it as complete
    Clamp count to INT_MAX in both shims before the call. POSIX allows read/write to move fewer bytes than requested so callers loop for the rest, and normal-sized I/O is unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant