ID:               29044
 Updated by:       [EMAIL PROTECTED]
 Reported By:      tomas_matousek at hotmail dot com
-Status:           No Feedback
+Status:           Open
 Bug Type:         Reproducible crash
 Operating System: *
-PHP Version:      5.0.0RC3
+PHP Version:      5.2.5
 New Comment:

Reopening this bug because I reproduced it today on 5.2.5 and on HEAD
and was about to raise my own bug for this.  The problem is still
clearly present from code inspection. Since this bug was originally
raised the technique proposed by Tomas has been used successfully in
several other recursive array functions such as for example
array_walk_recursive and array_merge_recursive. I think compact could be
fixed in the same way. 

I have a more extensive test case than the one Tomas supplied which I
will commit to head but not to the 5.3 and 5.2 branches (to avoid adding
breaking tests to stable branches.) The test case will be called
compact_variation1.phpt


Previous Comments:
------------------------------------------------------------------------

[2005-03-16 01:00:06] php-bugs at lists dot php dot net

No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".

------------------------------------------------------------------------

[2005-03-06 20:36:46] [EMAIL PROTECTED]

Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip



------------------------------------------------------------------------

[2004-07-07 11:13:40] tomas_matousek at hotmail dot com

I don't think it very hard. You can add a flag to each array, e.g. bool
visited, which will be false on array creation. You set the flag to true
when going down the recursion and clears it on return. Than it suffice
to test whether the flag has been set.

Functions such print_r does detect recursion in some way.

------------------------------------------------------------------------

[2004-07-07 11:05:41] [EMAIL PROTECTED]

Nothing much we could do about it. 
Detecting a recursion at the same level, as in your example, is easy
but detecting multi-level recursion is very hard. Also it would slow
down the function very much and require lots of memory when it is used
with multi level arrays.

Maybe we can disallow array references or something like that. Patch is
here:

http://marcus-boerger.de/php/ext/bug29044.diff.txt

please try.

------------------------------------------------------------------------

[2004-07-07 10:39:37] tomas_matousek at hotmail dot com

Description:
------------
The compact() function crashes (terminates PHP process) if an array
with infinite recursion is passed to it.

Reproduce code:
---------------
$a = array(&$a);
compact($a);

Expected result:
----------------
none

Actual result:
--------------
crash


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=29044&edit=1

Reply via email to