Skip to content

Commit 9b71c61

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: zend_API: Do not overwrite `readonly` properties in `object_properties_load()` (#19767)
2 parents 3230588 + 215ebbb commit 9b71c61

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

Zend/zend_API.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,14 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties)
17611761
property_info &&
17621762
(property_info->flags & ZEND_ACC_STATIC) == 0) {
17631763
zval *slot = OBJ_PROP(object, property_info->offset);
1764+
if (UNEXPECTED((property_info->flags & ZEND_ACC_READONLY) && !Z_ISUNDEF_P(slot))) {
1765+
if (Z_PROP_FLAG_P(slot) & IS_PROP_REINITABLE) {
1766+
Z_PROP_FLAG_P(slot) &= ~IS_PROP_REINITABLE;
1767+
} else {
1768+
zend_readonly_property_modification_error(property_info);
1769+
return;
1770+
}
1771+
}
17641772
zval_ptr_dtor(slot);
17651773
ZVAL_COPY_VALUE(slot, prop);
17661774
zval_add_ref(slot);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-19765: object_properties_load() bypasses readonly property checks
3+
--FILE--
4+
<?php
5+
6+
use Random\Engine\Mt19937;
7+
use Random\Engine\PcgOneseq128XslRr64;
8+
use Random\Randomizer;
9+
10+
try {
11+
$r = new Randomizer(new Mt19937());
12+
$r->__unserialize([['engine' => new PcgOneseq128XslRr64()]]);
13+
} catch (Exception $error) {
14+
echo $error->getMessage() . "\n";
15+
}
16+
var_dump($r->engine::class);
17+
18+
?>
19+
--EXPECT--
20+
Invalid serialization data for Random\Randomizer object
21+
string(21) "Random\Engine\Mt19937"

ext/random/tests/03_randomizer/gh_9186_unserialize.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Fix GH-9186 @strict-properties can be bypassed using unserialization
2+
GH-9186: @strict-properties can be bypassed using unserialization
33
--FILE--
44
<?php
55

0 commit comments

Comments
 (0)