Skip to content

Commit d812ea3

Browse files
committed
Fix ArrayIterator unserialize uninitialized properties HashTable
1 parent 10dad92 commit d812ea3

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

Zend/tests/weakrefs/gh22049.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
GH-22049: ArrayIterator clone after malformed unserialize should not assert
3+
--FILE--
4+
<?php
5+
6+
$payload = 'O:13:"ArrayIterator":3:{'
7+
. 's:1:"0";i:0;'
8+
. 's:1:"1";a:0:{}'
9+
. 's:1:"2";a:2:{i:0;i:0;i:1;i:0;}'
10+
. '}';
11+
12+
$obj = unserialize($payload);
13+
14+
$clone = clone $obj;
15+
16+
echo "OK\n";
17+
?>
18+
--EXPECTF--
19+
Deprecated: Creation of dynamic property ArrayIterator::$0 is deprecated in %s on line %d
20+
21+
Deprecated: Creation of dynamic property ArrayIterator::$1 is deprecated in %s on line %d
22+
OK

Zend/zend_API.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,13 @@ ZEND_API void object_properties_load(zend_object *object, const HashTable *prope
17781778
ZSTR_VAL(object->ce->name), h);
17791779
}
17801780

1781+
HashTable *ht = zend_std_get_properties_ex(object);
1782+
1783+
if (UNEXPECTED(HT_FLAGS(ht) & HASH_FLAG_UNINITIALIZED)) {
1784+
zend_hash_real_init_mixed(ht);
1785+
HT_FLAGS(ht) &= ~HASH_FLAG_UNINITIALIZED;
1786+
}
1787+
17811788
prop = zend_hash_index_update(zend_std_get_properties_ex(object), h, prop);
17821789
zval_add_ref(prop);
17831790
}

0 commit comments

Comments
 (0)