com php-src: Fixed bug #76800 (foreach inconsistent if array modified during loop): NEWS Zend/tests/bug76800.phpt Zend/zend_hash. c

From: Date: Fri, 14 Sep 2018 07:28:31 +0000
Subject: com php-src: Fixed bug #76800 (foreach inconsistent if array modified during loop): NEWS Zend/tests/bug76800.phpt Zend/zend_hash. c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-103105@lists.php.net to get a copy of this message
Commit: 3bc4a63fc27768c665fcbc101db4e579c761833b Author: Dmitry Stogov <dmitry@zend.com> Fri, 14 Sep 2018 10:28:31 +0300 Parents: 83685b52588ed62217abc07dec6b048ba580f137 Branches: PHP-7.2 PHP-7.3 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=3bc4a63fc27768c665fcbc101db4e579c761833b Log: Fixed bug #76800 (foreach inconsistent if array modified during loop) Bugs: https://bugs.php.net/76800 Changed paths: M NEWS A Zend/tests/bug76800.phpt M Zend/zend_hash.c Diff: diff --git a/NEWS b/NEWS index 8e9468e..952182f 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2018, PHP 7.2.11 +- Core: + . Fixed bug #76800 (foreach inconsistent if array modified during loop). + (Dmitry) + - Opcache: . Fixed bug #76832 (ZendOPcache.MemoryBase periodically deleted by the OS). (Anatol) diff --git a/Zend/tests/bug76800.phpt b/Zend/tests/bug76800.phpt new file mode 100644 index 0000000..d7f6d80 --- /dev/null +++ b/Zend/tests/bug76800.phpt @@ -0,0 +1,13 @@ +--TEST-- +Bug #76800 (foreach inconsistent if array modified during loop) +--FILE-- +<?php +$arr = [1 => 1, 3 => 3]; // [1 => 1, 2 => 3] will print both keys +foreach($arr as $key => &$val) { // without & will print both keys + echo "See key {$key}\n"; + $arr[0] = 0; // without this line will print both keys + unset($arr[0]); +} +--EXPECT-- +See key 1 +See key 3 diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c index f1b0c9b..8093869 100644 --- a/Zend/zend_hash.c +++ b/Zend/zend_hash.c @@ -932,9 +932,11 @@ ZEND_API int ZEND_FASTCALL zend_hash_rehash(HashTable *ht) if (UNEXPECTED(ht->nInternalPointer == i)) { ht->nInternalPointer = j; } - if (UNEXPECTED(i == iter_pos)) { - zend_hash_iterators_update(ht, i, j); - iter_pos = zend_hash_iterators_lower_pos(ht, iter_pos + 1); + if (UNEXPECTED(i >= iter_pos)) { + do { + zend_hash_iterators_update(ht, iter_pos, j); + iter_pos = zend_hash_iterators_lower_pos(ht, iter_pos + 1); + } while (iter_pos < i); } q++; j++;

« previous php.cvs (#103105) next »