Bug #71154 [NEW]: Incorrect HT iterator invalidation causes iterator reuse
| From: | nikic@php.net | Date: | Thu, 17 Dec 2015 20:35:06 +0000 |
| Subject: | Bug #71154 [NEW]: Incorrect HT iterator invalidation causes iterator reuse | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-197978@lists.php.net to get a copy of this message | ||
From: nikic
Operating system:
PHP version: 7.0Git-2015-12-17 (Git)
Package: Scripting Engine problem
Bug Type: Bug
Bug description:Incorrect HT iterator invalidation causes iterator reuse
Description:
------------
When iterators are removed on HT destruction we NULL out iter->ht
entries. This will allow the iter to be reused. However it may still be
in use by the foreach loop. In this case one iter will be shared between
two loops/iterators.
Test script:
---------------
<?php
$array = [1, 2, 3];
foreach ($array as &$ref) {
/* Free array, causing free of iterator */
$array = [];
/* Reuse the iterator.
* However it will also be reused on next foreach iteration */
$it = new ArrayIterator([1, 2, 3]);
$it->rewind();
}
var_dump($it->current());
Expected result:
----------------
int(1)
Actual result:
--------------
NULL
--
Edit bug report at https://bugs.php.net/bug.php?id=71154&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71154&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71154&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71154&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71154&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71154&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71154&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71154&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71154&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71154&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71154&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71154&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71154&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71154&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71154&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71154&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71154&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71154&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71154&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71154&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71154&r=mysqlcfg