Skip to content

Guard var_dump()/debug_zval_dump() against native stack overflow#22871

Open
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/var-dump-deep-stack-guard
Open

Guard var_dump()/debug_zval_dump() against native stack overflow#22871
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/var-dump-deep-stack-guard

Conversation

@iliaal

@iliaal iliaal commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

A deeply nested array or object passed to var_dump() or debug_zval_dump() overflows the native C stack and segfaults. The object path of var_dump() and serialize() already guard their recursion with ZEND_CHECK_STACK_LIMIT; the array element helper and both debug_zval_dump() helpers were missing it. var_export() overflows the same way but needs a throw-based guard, left for a separate change.

$a = [];
for ($i = 0; $i < 100000; $i++) { $a = [$a]; }
var_dump($a); // SIGSEGV before this change

php_object_property_dump() and serialize() already check
ZEND_CHECK_STACK_LIMIT before recursing, but php_array_element_dump()
and both debug_zval_dump() element helpers do not, so a deeply nested
array or object crashes the process instead of printing "nesting level
too deep". Add the same guard to those three helpers. var_export()
overflows the same way but needs a throw-based guard, left for a
separate change.
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