Skip to content

Guard var_dump()/debug_zval_dump() against native stack overflow - #190

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

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

Conversation

@iliaal

@iliaal iliaal commented Jul 23, 2026

Copy link
Copy Markdown
Owner

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 and degrade to "nesting level too deep" or a controlled Error; the array element helper and both debug_zval_dump() helpers were missing the check. This adds it to the three unguarded helpers. var_export() overflows the same way but emits PHP code, so it needs a throw rather than an inline notice, left for a separate change.

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

@iliaal
iliaal force-pushed the fix/var-dump-deep-stack-guard branch from e60c8b9 to be5f442 Compare July 23, 2026 12:50
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.
@iliaal
iliaal force-pushed the fix/var-dump-deep-stack-guard branch from be5f442 to ab25673 Compare July 23, 2026 13:21
@iliaal

iliaal commented Jul 23, 2026

Copy link
Copy Markdown
Owner Author

Promoted upstream: php#22871

@iliaal iliaal closed this Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant