Skip to content

ext/ftp: fix out-of-bounds read in ftp_get() ASCII CRLF translation#22328

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/ftp-get-ascii-crlf-overread
Open

ext/ftp: fix out-of-bounds read in ftp_get() ASCII CRLF translation#22328
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/ftp-get-ascii-crlf-overread

Conversation

@iliaal

@iliaal iliaal commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant