#19103 [Opn->Csd]: print_r infinite recursion bug and probable code fix

From: Date: Wed, 28 Aug 2002 09:50:31 +0000
Subject: #19103 [Opn->Csd]: print_r infinite recursion bug and probable code fix
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-18015@lists.php.net to get a copy of this message
ID: 19103 Updated by: derick@php.net Reported By: mtf@maximasystems.com -Status: Open +Status: Closed Bug Type: Scripting Engine problem Operating System: Linux PHP Version: 4.2.2 New Comment: This bug has been fixed in CVS. In case this was a PHP problem, snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. In case this was a documentation problem, the fix will show up soon at http://www.php.net/manual/. In case this was a PHP.net website problem, the change will show up on the PHP.net site and on the mirror sites in short time. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2002-08-26 06:41:35] mtf@maximasystems.com The infinite recursion bug in print_r still appears to be there as can be demonstrated by this little script: <?php $tmp = array(); $tmp2 = array(); $tmp3 = array(); $tmp[] =& $tmp2; $tmp[] =& $tmp3; $tmp2[] =& $tmp; $tmp2[] =& $tmp3; $tmp3[] =& $tmp; $tmp3[] =& $tmp2; print_r($tmp); ?> I have looked into the code and I believe the bug lies in zend_print_zval_r_ex(). if (++expr->value.ht->nApplyCount>1) { ZEND_PUTS(" *RECURSION*"); expr->value.ht->nApplyCount=0; return; } seems to be wrong. I believe it should read: if (++expr->value.ht->nApplyCount>1) { ZEND_PUTS(" *RECURSION*"); expr->value.ht->nApplyCount--; return; } and the same change should be made lower down for the objects. The current code spots the recursion because the counter is 1 and increased to 2, but then effectively hides that state from anything else by resetting the counter to 0. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=19103&edit=1

« previous php.bugs (#18015) next »