Skip to content

Fix GH-23089: stack overflow in array_merge_recursive() - #25406

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

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

Conversation

@akasakariko

Copy link
Copy Markdown

Fixes #23089

Check the Zend stack limit in array_merge_recursive() so deeply nested merges throw an Error before exhausting the native stack, using the same guard as array_replace_recursive()

Continues #23091, which was closed without merging; the object cleanup raised in that review is already present through #23340

The original input still encounters the independent array destruction overflow in #15869 during shutdown after reporting the Error, which also reproduces with the merge call removed

The regression frees its input iteratively to isolate recursive merging and runs under AddressSanitizer

Validation on macOS arm64

  • Debug NTS Standard and Zend suite: 8296 passed, 631 skipped, 1 expected failure
  • Debug ZTS with AddressSanitizer array tests and the next index overflow regression: 840 passed, 14 skipped
  • Original input with iterative cleanup and tracing JIT: catches Error and exits normally in both builds
  • Additional ASan stack checks: existing stack_limit_002 and stack_limit_004 Fiber failures reproduced on the unmodified baseline

Check the Zend stack limit before descending into nested arrays
Add a regression test with iterative input cleanup to isolate the merge
failure from the separate array destruction overflow under AddressSanitizer

Continues the stack guard proposed in phpGH-23091
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