Skip to content

Fix GH-23088: Stack overflow when comparing deeply nested arrays - #23090

Open
lazerg wants to merge 1 commit into
php:PHP-8.4from
lazerg:fix/gh-23088-array-compare-stack-limit
Open

Fix GH-23088: Stack overflow when comparing deeply nested arrays#23090
lazerg wants to merge 1 commit into
php:PHP-8.4from
lazerg:fix/gh-23088-array-compare-stack-limit

Conversation

@lazerg

@lazerg lazerg commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Comparing two deeply nested arrays recurses through zend_compare_arrays -> zend_compare_symbol_tables -> zend_hash_compare once per nesting level, and nothing bounds that recursion. zend_hash_compare() only guards against cycles, so a non-cyclic array a few tens of thousands of levels deep runs the C stack out and the process dies with a segfault. === crashes the same way through zend_is_identical().

Both now check the stack limit before descending and throw an Error instead, the same way zend_std_compare_objects() already handles the object case.

Fixes GH-23088

@lazerg
lazerg force-pushed the fix/gh-23088-array-compare-stack-limit branch 3 times, most recently from aa11ff5 to 983de1f Compare August 6, 2026 16:01
@lazerg
lazerg force-pushed the fix/gh-23088-array-compare-stack-limit branch from 983de1f to e0c17b3 Compare August 6, 2026 16:19
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