php.net |  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
Description:
------------
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:
---------------
<?php
function myfunc($value,$key) { echo "value: $value, key: $key \n";}
$a=array(array(),"foo"=>"bar");
$a[0][]=&$a;
array_walk_recursive($a,"myfunc");
echo "reached end \n";
?>

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

Actual result:
--------------
Segmentation fault


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-02 10:05 UTC] tony2001@php.net
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
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 23:01:29 2024 UTC