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:
  Fix GH-16054: Segmentation fault when resizing hash table iterator list while adding
This commit is contained in:
Niels Dossche
2024-09-25 21:08:36 +02:00
3 changed files with 24 additions and 4 deletions

2
NEWS
View File

@@ -4,6 +4,8 @@ PHP NEWS
- Core:
. Fixed bug GH-16040 (Use-after-free of object released in hook). (ilutov)
. Fixed bug GH-16054 (Segmentation fault when resizing hash table iterator
list while adding). (nielsdos)
- DOM:
. Fixed bug GH-16039 (Segmentation fault (access null pointer) in

View File

@@ -2345,17 +2345,20 @@ static zend_always_inline bool zend_array_dup_element(HashTable *source, HashTab
// We need to duplicate iterators to be able to search through all copy-on-write copies to find the actually iterated HashTable and position back
static void zend_array_dup_ht_iterators(HashTable *source, HashTable *target) {
HashTableIterator *iter = EG(ht_iterators);
HashTableIterator *end = iter + EG(ht_iterators_used);
uint32_t iter_index = 0;
uint32_t end_index = EG(ht_iterators_used);
while (iter != end) {
while (iter_index != end_index) {
HashTableIterator *iter = &EG(ht_iterators)[iter_index];
if (iter->ht == source) {
uint32_t copy_idx = zend_hash_iterator_add(target, iter->pos);
/* Refetch iter because the memory may be reallocated. */
iter = &EG(ht_iterators)[iter_index];
HashTableIterator *copy_iter = EG(ht_iterators) + copy_idx;
copy_iter->next_copy = iter->next_copy;
iter->next_copy = copy_idx;
}
iter++;
iter_index++;
}
}

View File

@@ -0,0 +1,15 @@
--TEST--
GH-16054 (Segmentation fault when resizing hash table iterator list while adding)
--FILE--
<?php
$multi_array = ['zero'];
$multi_array[] =& $multi_array;
$it = new RecursiveTreeIterator(new RecursiveArrayIterator($multi_array), 0);
$counter = 0;
foreach ($it as $k => $v) {
if (++$counter > 200) break;
}
echo "ok\n";
?>
--EXPECT--
ok