Skip to content

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

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

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

Conversation

@iliaal

@iliaal iliaal commented Jun 16, 2026

Copy link
Copy Markdown
Owner

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
@iliaal iliaal force-pushed the fix/ftp-get-ascii-crlf-overread branch from e9abdba to ba22647 Compare June 16, 2026 01:35
@iliaal

iliaal commented Jun 16, 2026

Copy link
Copy Markdown
Owner Author

Submitted upstream as php#22328.

@iliaal iliaal closed this Jun 16, 2026
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