Skip to content

Fix GH-23089: stack overflow in array_merge_recursive() with deep arrays - #23091

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

Fix GH-23089: stack overflow in array_merge_recursive() with deep arrays#23091
lazerg wants to merge 1 commit into
php:PHP-8.4from
lazerg:fix/gh-23089-array-merge-recursive-stack-limit

Conversation

@lazerg

@lazerg lazerg commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

php_array_merge_recursive() recurses once per nesting level with no stack check, so array_merge_recursive() on a deeply nested array exhausts the native stack and the process dies with a segfault.

This adds the same stack limit check ext/standard already uses in var.c and http.c, so the call throws an Error instead of crashing.

array_replace_recursive() has the same unguarded recursion. I kept this to the reported crash, but can cover it here too if you'd rather have both in one go.

Fixes #23089.

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