Bug #72107 [Opn->Ver]: Infinite Recursion in Array Structure

From: Date: Mon, 31 May 2021 15:33:49 +0000
Subject: Bug #72107 [Opn->Ver]: Infinite Recursion in Array Structure
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234125@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=72107&edit=1 ID: 72107 Updated by: cmb@php.net Reported by: php at abiusx dot com Summary: Infinite Recursion in Array Structure -Status: Open +Status: Verified Type: Bug Package: Arrays related Operating System: OS X PHP Version: 7.0.5 Block user comment: N Private report: N New Comment: Indeed, (un)serialization doesn't look quite right[1], and the loop hangs for me (PHP-7.4). [1] <https://3v4l.org/eqU8f> Previous Comments: ------------------------------------------------------------------------ [2016-04-26 14:43:48] php at abiusx dot com 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 this bug report at https://bugs.php.net/bug.php?id=72107&edit=1

« previous php.bugs (#234125) next »