Skip to content

Commit 89fe484

Browse files
committed
Fix bugs in SplFixedArray unserialization
A typed property of an object properties table is an indirect pointer (IS_IND) to a typed reference (IS_REF). Neither of those should be in the backing array after unserializing an SplFixedArray (see SplFixedArray::fromArray()). I missed this initially when reviewing phpGH-9354
1 parent da9db14 commit 89fe484

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

ext/spl/spl_fixedarray.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,8 @@ PHP_METHOD(SplFixedArray, __wakeup)
576576

577577
spl_fixedarray_init(&intern->array, size);
578578

579-
ZEND_HASH_FOREACH_VAL(intern_ht, data) {
580-
ZVAL_COPY(&intern->array.elements[index], data);
579+
ZEND_HASH_FOREACH_VAL_IND(intern_ht, data) {
580+
ZVAL_COPY_DEREF(&intern->array.elements[index], data);
581581
index++;
582582
} ZEND_HASH_FOREACH_END();
583583

@@ -640,7 +640,7 @@ PHP_METHOD(SplFixedArray, __unserialize)
640640
intern->array.size = 0;
641641
ZEND_HASH_FOREACH_STR_KEY_VAL(data, key, elem) {
642642
if (key == NULL) {
643-
ZVAL_COPY(&intern->array.elements[intern->array.size], elem);
643+
ZVAL_COPY_DEREF(&intern->array.elements[intern->array.size], elem);
644644
intern->array.size++;
645645
} else {
646646
Z_TRY_ADDREF_P(elem);

ext/spl/tests/fixedarray_025.phpt

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
SPL: FixedArray: __wakeup
3+
--FILE--
4+
<?php
5+
#[AllowDynamicProperties]
6+
class MyFixedArray extends SplFixedArray {
7+
public stdClass $x;
8+
public $y;
9+
}
10+
$a = new MyFixedArray();
11+
$a->x = new stdClass();
12+
$y = new ArrayObject();
13+
$a->y = &$y;
14+
$a->z = new stdClass();
15+
$x = &$a->x;
16+
$a->__wakeup();
17+
var_dump($a);
18+
?>
19+
--EXPECTF--
20+
object(MyFixedArray)#%d (3) {
21+
[0]=>
22+
object(stdClass)#%d (0) {
23+
}
24+
[1]=>
25+
object(ArrayObject)#%d (1) {
26+
["storage":"ArrayObject":private]=>
27+
array(0) {
28+
}
29+
}
30+
[2]=>
31+
object(stdClass)#%d (0) {
32+
}
33+
}

0 commit comments

Comments
 (0)