Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Guard igbinary_serialize() against C stack overflow on deep nesting#416

Open
iliaal wants to merge 1 commit into
igbinary:masterigbinary/igbinary:masterfrom
iliaal:fix/serialize-stack-limitiliaal/igbinary:fix/serialize-stack-limitCopy head branch name to clipboard
Open

Guard igbinary_serialize() against C stack overflow on deep nesting#416
iliaal wants to merge 1 commit into
igbinary:masterigbinary/igbinary:masterfrom
iliaal:fix/serialize-stack-limitiliaal/igbinary:fix/serialize-stack-limitCopy head branch name to clipboard

Conversation

@iliaal

@iliaal iliaal commented Jun 1, 2026

Copy link
Copy Markdown

igbinary_serialize_zval() recurses once per nesting level with no depth or stack-limit check, so a deep enough array or object overflows the C stack and segfaults the process. Core's serialize() guards the same recursion via php_serialize_check_stack_limit() (added in 8.3) and throws a catchable Error; igbinary crashes where core recovers. This is the serialize-side counterpart to the unserialize cap in #414.

Reproducer (segfaults before this change):

$a = "x";
for ($i = 0; $i < 100000; $i++) $a = [$a];
igbinary_serialize($a);

The fix checks zend_call_stack_overflowed(EG(stack_limit)) at the top of igbinary_serialize_zval() and raises via zend_call_stack_size_error(). No-op without ZEND_CHECK_STACK_LIMIT (PHP < 8.3), where core had no guard either. Test mirrors ext/standard/tests/serialize/gh15169.phpt.

@iliaal iliaal force-pushed the fix/serialize-stack-limit branch from ece4404 to 0df199d Compare June 1, 2026 23:52
igbinary_serialize_zval() recurses once per nesting level with no depth
or stack check, so a deeply nested array or object overflows the C stack
and crashes the process. Mirror php_serialize_check_stack_limit() from
ext/standard/var.c: check zend_call_stack_overflowed() at the top of the
recursion and raise a catchable Error instead. No-op on builds without
the Zend stack-limit feature (PHP < 8.3), matching core.
@iliaal iliaal force-pushed the fix/serialize-stack-limit branch from 0df199d to 945829a Compare June 1, 2026 23:58
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.