Bug #72107 [NEW]: Infinite Recursion in Array Structure
| From: | php at abiusx dot com | Date: | Tue, 26 Apr 2016 14:43:54 +0000 |
| Subject: | Bug #72107 [NEW]: Infinite Recursion in Array Structure | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-200784@lists.php.net to get a copy of this message | ||
From: php at abiusx dot com
Operating system: OS X
PHP version: 7.0.5
Package: Arrays related
Bug Type: Bug
Bug description:Infinite Recursion in Array Structure
Description:
------------
By creating an array structure in the following format:
$a=[];
$a['ref']=&$a;
$a['val']=$a;
Any PHP-only attempt at discovering this recursion will fail. Also,
structures like RecursiveIterators will loop infinitely,
unserialize(serialize($a)) also drops out the val part.
Generally PHP behaves very weird and unexpectedly. I have not traced
this in the Zend engine to see what is causing it, but my hypothesis is
that accessing $a['val'] is creating a new copy of it every time (and my
PHP-side tests confirm this).
Test script:
---------------
$a=['ref'=>&$a];
$a['val']=$a;
var_dump($a); //normal, as expected
var_dump(unserialize(serialize($a))); //half-arsed
foreach (new RecursiveIteratorIterator(new RecursiveArrayIterator($a))
as $k=>$v)
echo $k,"=>",@$v,PHP_EOL; //infinite loop
Expected result:
----------------
At least RecursiveIterators should be able to distinguish this behavior,
if serialize can not handle it. Or PHP internals should be changed in a
way that this does not happen.
Or these examples be marked as dangerous because they can possibly break
applications.
Actual result:
--------------
Infinite Loop
--
Edit bug report at https://bugs.php.net/bug.php?id=72107&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=72107&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=72107&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=72107&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=72107&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=72107&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=72107&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=72107&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=72107&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=72107&r=support
Expected behavior: https://bugs.php.net/fix.php?id=72107&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=72107&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=72107&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=72107&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=72107&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=72107&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=72107&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=72107&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=72107&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=72107&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=72107&r=mysqlcfg