Skip to content

Commit c5fa769

Browse files
committed
Fix Randomizer::__serialize() wrt INDIRECTs
First follow-up to GH-20102. INDIRECTs must never get exposed to userland. The simple solution is to duplicate the properties array. Closes GH-20103.
1 parent b16761e commit c5fa769

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ PHP NEWS
77
. Fixed bug GH-20073 (Assertion failure in WeakMap offset operations on
88
reference). (nielsdos)
99

10+
- Random:
11+
. Fix Randomizer::__serialize() w.r.t. INDIRECTs. (nielsdos)
12+
1013
23 Oct 2025, PHP 8.3.27
1114

1215
- Core:

ext/random/randomizer.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,7 @@ PHP_METHOD(Random_Randomizer, __serialize)
468468
ZEND_PARSE_PARAMETERS_NONE();
469469

470470
array_init(return_value);
471-
ZVAL_ARR(&t, zend_std_get_properties(&randomizer->std));
472-
Z_TRY_ADDREF(t);
471+
ZVAL_ARR(&t, zend_array_dup(zend_std_get_properties(&randomizer->std)));
473472
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &t);
474473
}
475474
/* }}} */
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Random: Engine: __serialize() must not expose INDIRECTs
3+
--FILE--
4+
<?php
5+
6+
$randomizer = new Random\Randomizer(null);
7+
var_dump($randomizer->__serialize());
8+
9+
?>
10+
--EXPECT--
11+
array(1) {
12+
[0]=>
13+
array(1) {
14+
["engine"]=>
15+
object(Random\Engine\Secure)#2 (0) {
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)