Skip to content

Commit 8491730

Browse files
committed
Fix duplicate dynamic properties in hooked object iterator properties table
Ouch, Z_TRY_ADDREF_P() uses pz twice... Also make sure we actually reserve enough Buckets for all dynamic properties. Fixes OSS-Fuzz #382922236 Closes GH-17085
1 parent 7b5141b commit 8491730

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ PHP NEWS
77
. Fixed bug GH-17061 (Now Number::round() does not remove trailing zeros).
88
(Saki Takamachi)
99

10+
- Core:
11+
. Fixed bug OSS-Fuzz #382922236 (Duplicate dynamic properties in hooked object
12+
iterator properties table). (ilutov)
13+
1014
- DBA:
1115
. Skip test if inifile is disabled. (orlitzky)
1216

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
OSS-Fuzz #382922236: Duplicate dynamic properties in hooked object iterator properties table
3+
--FILE--
4+
<?php
5+
6+
#[AllowDynamicProperties]
7+
class C {
8+
public $a {
9+
get => 42;
10+
}
11+
}
12+
13+
$obj = new C();
14+
$b = &$obj->b;
15+
unset($b);
16+
echo json_encode($obj);
17+
18+
?>
19+
--EXPECT--
20+
{"a":42,"b":null}

Zend/zend_property_hooks.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ static uint32_t zho_num_backed_props(zend_object *zobj)
4444
static zend_array *zho_build_properties_ex(zend_object *zobj, bool check_access, bool force_ptr, bool include_dynamic_props)
4545
{
4646
zend_class_entry *ce = zobj->ce;
47-
zend_array *properties = zend_new_array(ce->default_properties_count);
47+
zend_array *properties = zend_new_array(include_dynamic_props && zobj->properties
48+
? zend_hash_num_elements(zobj->properties)
49+
: ce->default_properties_count);
4850
zend_hash_real_init_mixed(properties);
4951

5052
/* Build list of parents */
@@ -105,7 +107,8 @@ static zend_array *zho_build_properties_ex(zend_object *zobj, bool check_access,
105107
zend_string *prop_name;
106108
zval *prop_value;
107109
ZEND_HASH_FOREACH_STR_KEY_VAL_FROM(zobj->properties, prop_name, prop_value, zho_num_backed_props(zobj)) {
108-
Z_TRY_ADDREF_P(_zend_hash_append(properties, prop_name, prop_value));
110+
zval *tmp = _zend_hash_append(properties, prop_name, prop_value);
111+
Z_TRY_ADDREF_P(tmp);
109112
} ZEND_HASH_FOREACH_END();
110113
}
111114

0 commit comments

Comments
 (0)