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#416iliaal wants to merge 1 commit intoigbinary:masterigbinary/igbinary:masterfrom iliaal:fix/serialize-stack-limitiliaal/igbinary:fix/serialize-stack-limitCopy head branch name to clipboard
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
ece4404 to
0df199d
Compare
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.
0df199d to
945829a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):
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.