Skip to content

Commit d9cbc31

Browse files
ndosscheiluuu1994
authored andcommitted
Fix hooked object properties overflow
The computed number of properties using zend_hash_num_elements(zobj->properties) is incorrect when the object contains virtual properties. We don't have a trivial way to find the number of properties virtual properties that need to be added to this number, so just append with zend_hash_add_new() instead. Fixes phpGH-20479 Closes phpGH-20988
1 parent 4367315 commit d9cbc31

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ PHP NEWS
1515
. Fix OSS-Fuzz #438780145 (Nested finally with repeated return type check may
1616
uaf). (ilutov)
1717
. Fixed bug GH-20905 (Lazy proxy bailing __clone assertion). (ilutov)
18+
. Fixed bug GH-20479 (Hooked object properties overflow). (ndossche)
1819

1920
- Date:
2021
. Update timelib to 2022.16. (Derick)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
GH-20479: Hooked object properties overflow
3+
--CREDITS--
4+
Viet Hoang Luu (@vi3tL0u1s)
5+
--FILE--
6+
<?php
7+
8+
#[AllowDynamicProperties]
9+
class Trigger {
10+
public $a = 'x';
11+
public $b = 'x';
12+
public $c = 'x';
13+
public $d = 'x';
14+
public $e = 'x';
15+
public $f = 'x';
16+
public string $trigger {
17+
get {
18+
return 'trigger';
19+
}
20+
}
21+
}
22+
23+
$obj = new Trigger();
24+
// Add 2 dynamic props
25+
$obj->g = $obj->h = 'x';
26+
var_export($obj);
27+
28+
?>
29+
--EXPECT--
30+
\Trigger::__set_state(array(
31+
'a' => 'x',
32+
'b' => 'x',
33+
'c' => 'x',
34+
'd' => 'x',
35+
'e' => 'x',
36+
'f' => 'x',
37+
'trigger' => 'trigger',
38+
'h' => 'x',
39+
'g' => 'x',
40+
))

Zend/zend_property_hooks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static zend_array *zho_build_properties_ex(zend_object *zobj, bool check_access,
121121
if (Z_TYPE_P(prop_value) == IS_INDIRECT) {
122122
continue;
123123
}
124-
zval *tmp = _zend_hash_append(properties, prop_name, prop_value);
124+
zval *tmp = zend_hash_add_new(properties, prop_name, prop_value);
125125
Z_TRY_ADDREF_P(tmp);
126126
} ZEND_HASH_FOREACH_END();
127127
}

0 commit comments

Comments
 (0)