|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42752 array_walk_recursive with recursive array depth>1 crashes
Submitted: 2007-09-25 07:27 UTC Modified: 2007-10-02 10:05 UTC
From: rob_nicholson at uk dot ibm dot com Assigned:
Status: Closed Package: Reproducible crash
PHP Version: 6CVS-2007-09-25 (snap) OS: windows XP, Ubuntu
Private report: No CVE-ID: None
 [2007-09-25 07:27 UTC] rob_nicholson at uk dot ibm dot com
array_walk_recursive contains code to detect recursion in arrays where the recursion depth is 1. But deeper recursion is not detected, leading to the code recursing until the stack depth becomes too great and a crash occurs.

It seems clear from the code that the problem is in php_array_walk in ext/standard/array.c. The following test only detects single level recursion:

                        if (thash == target_hash) {
                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "recursion detected");
                                 return 0;

Reproduce code:
function myfunc($value,$key) { echo "value: $value, key: $key \n";}
echo "reached end \n";

Expected result:
value: bar, key: foo
reached end

Actual result:
Segmentation fault


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-02 10:05 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC