Skip to content

ext/standard: Use fallible realloc for ASCII runs in htmlspecialchars() - #26079

Open
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/htmlspecialchars-oom-hard-limit
Open

iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/htmlspecialchars-oom-hard-limit

Conversation

@iliaal

@iliaal iliaal commented Dec 4, 2026

Copy link
Copy Markdown
Member

The ASCII-run copy added to htmlspecialchars() in GH-24145 grows the output with the infallible zend_string_safe_realloc(), by the length of the remaining input each time. With heavy entity expansion this overshoots memory_limit until the hard limit kills the process with SIGKILL, skipping shutdown functions. Use the fallible zend_string_safe_frealloc(), as the 128-byte growth below it does, so the request ends with the usual memory-limit fatal error.

The ASCII-run fast copy added to php_escape_html_entities_ex() in
97335aa used infallible zend_string_safe_realloc() instead of
zend_string_safe_frealloc(). On inputs with heavy entity expansion,
exceeding memory_limit keeps reallocating past the soft limit until the
hard limit terminates the process with SIGKILL and skips shutdown
handlers. Switch to zend_string_safe_frealloc() and release replaced on
failure, matching the reallocation immediately below it.
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