Re: [PATCH] New functions: array_replace[_recursive]
| From: | Matt Wilmas | Date: | Thu, 31 Jul 2008 16:48:21 +0000 |
| Subject: | Re: [PATCH] New functions: array_replace[_recursive] | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-39510@lists.php.net to get a copy of this message | ||
Hi Johannes,
----- Original Message -----
From: "Johannes Schlüter"
Sent: Thursday, July 31, 2008
> Matt,
>
> On Tue, 2008-07-22 at 10:52 -0500, Matt Wilmas wrote:
> > Adding these two array functions has been on the TODO for a while,
>
> The patch can quite easily be tricked into an endless recursion of
> php_array_replace_recursive() calls which will segfault:
>
> $ php -r '$a = array(); $a[] = &$a; $b = array(); $b[] = &$b;
> array_replace_recursive($a, $b);'
> Segmentation fault
>
> Some other cases were covered by PHP's recursion detection:
>
> $ php -r '$a = array(); $a[1] = &$a; $b = array(); $b[2] = &$b;
> array_replace_recursive($a, $b, array(&$a, &$b), array(&$b, &$a));'
>
> Warning: array_replace_recursive(): recursion detected in Command line
> code on line 1
>
> Can you try to add a detection for the first case?
Ugh, I hate that reference/recursion stuff! I have a hard time following
what's happening, and am not sure how some of those checks, etc. even work
in php_array_merge() (which I was working from). :-/ I tried changing a few
parts, and unfortunately couldn't fix it. I will look at it further when I
have some more time, and will of course let you know if it's fixed. Sorry.
:-(
Anyone else reading this and may be able to more easily see what's going
wrong? :^)
> johannes
- Matt