ext/ftp: fix out-of-bounds read in ftp_get() ASCII CRLF translation#22328
Open
iliaal wants to merge 1 commit into
Open
ext/ftp: fix out-of-bounds read in ftp_get() ASCII CRLF translation#22328iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
In ASCII mode ftp_get() scans each received block for '\r' and peeks at the next byte to collapse a CRLF pair to '\n'. When the '\r' is the last byte of a full FTP_BUFSIZE block, the *(s + 1) lookahead reads one byte past the data buffer; a server placing '\r' at offset 4095 of a 4096-byte read triggers it. Bound the lookahead to the received data, matching the guard ftp_readline() already uses. ftp_nb_continue_read() carries the trailing '\r' across reads via ftp->lastch and is unaffected. Closes phpGH-22328
e9abdba to
ba22647
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In ASCII mode ftp_get() peeks at the byte after each '\r' to fold CRLF into LF. When that '\r' is the last byte of a full FTP_BUFSIZE read, the lookahead reads one byte past the buffer; a server placing '\r' at offset 4095 of a 4096-byte read hits it (ASAN: heap-buffer-overflow read of size 1). Bound the lookahead to the received data, as ftp_readline() does. ftp_nb_continue_read() carries the trailing '\r' across reads and isn't affected.