From:             rob_nicholson at uk dot ibm dot com
Operating system: windows XP, Ubuntu
PHP version:      6CVS-2007-09-25 (snap)
PHP Bug Type:     Reproducible crash
Bug description:  array_walk_recursive with recursive array depth>1 crashes

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


-- 
Edit bug report at http://bugs.php.net/?id=42752&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42752&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42752&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42752&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42752&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42752&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42752&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42752&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42752&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42752&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42752&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42752&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42752&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42752&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42752&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42752&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42752&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42752&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42752&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42752&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42752&r=mysqlcfg

Reply via email to