Skip to content

Commit f08fe17

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

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.5.0RC1
44

5+
- Core:
6+
. Fixed bug GH-19765 (object_properties_load() bypasses readonly property
7+
checks). (timwolla)
58

69
11 Sep 2025, PHP 8.5.0beta3
710

Zend/zend_API.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,6 +1769,14 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties)
17691769
property_info &&
17701770
(property_info->flags & ZEND_ACC_STATIC) == 0) {
17711771
zval *slot = OBJ_PROP(object, property_info->offset);
1772+
if (UNEXPECTED((property_info->flags & ZEND_ACC_READONLY) && !Z_ISUNDEF_P(slot))) {
1773+
if (Z_PROP_FLAG_P(slot) & IS_PROP_REINITABLE) {
1774+
Z_PROP_FLAG_P(slot) &= ~IS_PROP_REINITABLE;
1775+
} else {
1776+
zend_readonly_property_modification_error(property_info);
1777+
return;
1778+
}
1779+
}
17721780
zval_ptr_dtor(slot);
17731781
ZVAL_COPY_VALUE(slot, prop);
17741782
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)