Skip to content

Fix GH-23113: stack overflow in array_replace_recursive() with deep arrays - #23124

Merged
arnaud-lb merged 2 commits into
php:PHP-8.4from
lazerg:fix/gh-23113-array-replace-recursive-stack-limit
Aug 10, 2026
Merged

Fix GH-23113: stack overflow in array_replace_recursive() with deep arrays#23124
arnaud-lb merged 2 commits into
php:PHP-8.4from
lazerg:fix/gh-23113-array-replace-recursive-stack-limit

Conversation

@lazerg

@lazerg lazerg commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

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

This is the follow-up I offered in #23091, applying the same stack limit check ext/standard already uses in var.c and http.c, so the call throws an Error instead of crashing.

Fixes #23113.

@arnaud-lb
arnaud-lb merged commit af1abdf into php:PHP-8.4 Aug 10, 2026
14 of 18 checks passed
arnaud-lb added a commit that referenced this pull request Aug 10, 2026
* PHP-8.5:
  Add a stack limit check in php_array_replace_recursive (#23124)
  Add a stack limit check in php_array_walk() (#23125)
@arnaud-lb

Copy link
Copy Markdown
Member

Thank you!

pull Bot pushed a commit to dolfly/php-src that referenced this pull request Aug 10, 2026
* PHP-8.4:
  Add a stack limit check in php_array_replace_recursive (php#23124)
  Add a stack limit check in php_array_walk() (php#23125)
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.

2 participants