Skip to content

ext/ftp: preserve bare CR bytes in ftp_get() ASCII mode#22364

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/ftp-get-ascii-bare-cr
Open

ext/ftp: preserve bare CR bytes in ftp_get() ASCII mode#22364
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/ftp-get-ascii-bare-cr

Conversation

@iliaal

@iliaal iliaal commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

In ASCII mode ftp_get() stripped every \r and re-emitted only a following \n, dropping bare CRs that aren't part of a CRLF (ba\rre arrived as bare). It now folds CRLF to LF but writes a lone \r through unchanged, carries a \r landing on the last byte of a read into the next read, and flushes it at EOF, so the boundary case matches the in-buffer case. ftp_nb_get() already did this via the lastch carry in ftp_nb_continue_read(). Follow-up to GH-22328, which fixed the out-of-bounds read in the same lookahead.

In ASCII mode ftp_get() stripped every '\r' and emitted only a following
'\n', dropping bare CR bytes not part of a CRLF sequence. Fold CRLF to
LF but write a lone '\r' through unchanged, carrying a '\r' on the final
byte of a read into the next read and flushing it at EOF, so the buffer
boundary behaves the same as the in-buffer case. ftp_nb_get() already
does this via the lastch carry in ftp_nb_continue_read().
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.

2 participants