1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.3' into PHP-8.4

* PHP-8.3:
  Stale array iterator pointer
This commit is contained in:
Ilija Tovilo
2025-09-03 18:15:35 +02:00
3 changed files with 32 additions and 2 deletions

1
NEWS
View File

@@ -9,6 +9,7 @@ PHP NEWS
due to signed int overflow). (ilutov)
. Fixed bug GH-19544 (GC treats ZEND_WEAKREF_TAG_MAP references as WeakMap
references). (Arnaud, timwolla)
. Fixed bug GH-19613 (Stale array iterator pointer). (ilutov)
- Date:
. Fixed date_sunrise() and date_sunset() with partial-hour UTC offset.

22
Zend/tests/gh19613.phpt Normal file
View File

@@ -0,0 +1,22 @@
--TEST--
GH-19613: Invalidated array iterator pointer after array separation
--FILE--
<?php
$a = [1];
$i = 0;
foreach ($a as &$v) {
$a[0] = $a;
foreach ($v as &$w) {
$w = $a;
if ($i++ == 64) {
die("===DONE===\n");
}
}
}
?>
--EXPECT--
===DONE===

View File

@@ -635,8 +635,15 @@ ZEND_API HashPosition ZEND_FASTCALL zend_hash_iterator_pos_ex(uint32_t idx, zval
&& EXPECTED(!HT_ITERATORS_OVERFLOW(ht))) {
HT_DEC_ITERATORS_COUNT(iter->ht);
}
SEPARATE_ARRAY(array);
ht = Z_ARRVAL_P(array);
/* Inlined SEPARATE_ARRAY() with updating of iterator when EG(ht_iterators) grows. */
if (UNEXPECTED(GC_REFCOUNT(ht) > 1)) {
ZVAL_ARR(array, zend_array_dup(ht));
GC_TRY_DELREF(ht);
iter = EG(ht_iterators) + idx;
ht = Z_ARRVAL_P(array);
}
if (EXPECTED(!HT_ITERATORS_OVERFLOW(ht))) {
HT_INC_ITERATORS_COUNT(ht);
}