Skip to content

Commit 2c508c4

Browse files
committed
Always remove HT iterators, even for uninit HT
Fixes oss-fuzz #31423.
1 parent e857936 commit 2c508c4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
HT iterator should be destroyed if array becomes empty during array_splice
3+
--FILE--
4+
<?php
5+
$a=[4];
6+
$i = 0;
7+
foreach ($a as &$r) {
8+
var_dump($r);
9+
$a = array_splice($a, 0);
10+
if (++$i == 2) break;
11+
}
12+
?>
13+
--EXPECT--
14+
int(4)
15+
int(4)

Zend/zend_hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1630,10 +1630,10 @@ ZEND_API void ZEND_FASTCALL zend_array_destroy(HashTable *ht)
16301630
} else if (EXPECTED(HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED)) {
16311631
goto free_ht;
16321632
}
1633-
zend_hash_iterators_remove(ht);
16341633
SET_INCONSISTENT(HT_DESTROYED);
16351634
efree(HT_GET_DATA_ADDR(ht));
16361635
free_ht:
1636+
zend_hash_iterators_remove(ht);
16371637
FREE_HASHTABLE(ht);
16381638
}
16391639

0 commit comments

Comments
 (0)