Skip to content

Commit 645e62b

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix hooked object properties overflow
2 parents 337cb37 + 6d02e51 commit 645e62b

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed
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)