[GIT-PULLS] [php-src] PR #23197: Fix stack overflow in count() with COUNT_RECURSIVE and deep arrays
[email protected] (lazerg)
| Newsgroups | php.git-pulls |
|---|---|
| Message-ID | <InZEsUFXJUabf6O72dTkejDAeEVPoWhwwVTy7KPg0Gk@main.internal.php.net> |
Pull Request: https://github.com/php/php-src/pull/23197 Author: lazerg `php_count_recursive()` recurses once per nesting level with no stack check, so `count($array, COUNT_RECURSIVE)` on a deeply nested array exhausts the native stack and the process dies with a segfault. This is the separate PR offered in #23125, applying the same stack limit check the neighbouring functions in ext/standard use, so the call throws an Error instead of crashing. There is no GitHub issue for it. The loop over the elements also breaks once the error is thrown, otherwise every remaining sibling recurses again and chains another Error onto the first one, and `count()` returns through `RETURN_THROWS()` in that case.