Skip to content

Zend: Reject INI input longer than INT_MAX in the scanner - #25192

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/parse-ini-string-length-guard
Open

iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/parse-ini-string-length-guard

Conversation

@iliaal

@iliaal iliaal commented Nov 4, 2026 •

Copy link
Copy Markdown
Member

The INT_MAX check in parse_ini_string() set the return value without returning, and its size_t subtraction wrapped above INT_MAX, so it never rejected anything. The INI scanner takes the buffer length as unsigned int and passes token lengths to int parameters, so reject input longer than INT_MAX in both scanner entry points instead, which covers parse_ini_file() as well. No test, since triggering it needs a 2 GiB input.

@jorgsowa jorgsowa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't UINT_MAX still too high? yyleng goes into int len in zend_ini_copy_typed_value() and zend_ini_escape_string(), so tokens over 2 GiB still abort:

parse_ini_file() has the same truncation in zend_ini_open_file_for_scanning().

Comment thread ext/standard/basic_functions.c Resolved
The INT_MAX check added to parse_ini_string() for bug #55622 set the
return value without returning, and its size_t subtraction wrapped for
strings longer than INT_MAX, so it never rejected anything. The scanner
takes the buffer length as unsigned int, truncating files and strings
longer than UINT_MAX, and passes token lengths to int parameters in
zend_ini_copy_typed_value() and zend_ini_escape_string(), which go
negative for tokens longer than INT_MAX. Reject input longer than INT_MAX
in zend_ini_open_file_for_scanning() and
zend_ini_prepare_string_for_scanning(), which covers parse_ini_file() and
parse_ini_string() alike, and drop the dead check.
@iliaal iliaal changed the title ext/standard: Fix the parse_ini_string() length guard Zend: Reject INI input longer than INT_MAX in the scanner Dec 6, 2026
@iliaal
iliaal force-pushed the fix/parse-ini-string-length-guard branch from 46c2e2f to 1e48110 Compare December 6, 2026 13:14
@iliaal

iliaal commented Dec 6, 2026

Copy link
Copy Markdown
Member Author

Right, moved the check into both scanner entry points with an INT_MAX limit, so parse_ini_file() is covered as well.

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