ext/standard: fix out-of-bounds access in the ftp:// directory stream#22768
Closed
iliaal wants to merge 1 commit into
Closed
ext/standard: fix out-of-bounds access in the ftp:// directory stream#22768iliaal wants to merge 1 commit into
iliaal wants to merge 1 commit into
Conversation
php_ftp_dirstream_read() sized the basename copy with MIN(sizeof(ent->d_name), ZSTR_LEN(basename) - 1) and wrote the terminator at [tmp_len - 1]. An empty listing line leaves a basename of length 1, so tmp_len is 0 and the NUL lands one byte before d_name; a slash-only line leaves length 0, so the subtraction underflows to SIZE_MAX and memcpy() reads 4096 bytes past the interned empty string. The same off-by-one truncated entry names that do not end in CRLF. Closes phpGH-22768
iliaal
force-pushed
the
std-ss002-ftp-dirstream
branch
from
July 16, 2026 16:40
7539a40 to
0653d3d
Compare
ndossche
approved these changes
Jul 16, 2026
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.
php_ftp_dirstream_read()sized the basename copy withMIN(sizeof, len - 1)and terminated at[tmp_len - 1]. An empty listing line gives a basename of length 1, so tmp_len is 0 and the terminator lands one byte before d_name; a slash-only line gives length 0, so len - 1 underflows to SIZE_MAX and memcpy reads 4096 bytes past the interned empty string. ASAN flags both. The same off-by-one truncated entry names that do not end in CRLF, which opendir-002 and opendir-004 had baked in as expected output.Floor: PHP-8.4.