Skip to content

Commit d6d8f24

Browse files
committed
Fix GH-20614: SplFixedArray incorrectly handles references in deserialization
All other code caters to dereferencing array elements, except the unserialize handler. This causes references to be present in the fixed array even though this seems not intentional as reference assign is otherwise impossible. On 8.5+ this causes an assertion failure. On 8.3+ this causes references to be present where they shouldn't be.
1 parent 8fe7930 commit d6d8f24

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

ext/spl/spl_fixedarray.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ PHP_METHOD(SplFixedArray, __unserialize)
652652
intern->array.size = 0;
653653
ZEND_HASH_FOREACH_STR_KEY_VAL(data, key, elem) {
654654
if (key == NULL) {
655-
ZVAL_COPY(&intern->array.elements[intern->array.size], elem);
655+
ZVAL_COPY_DEREF(&intern->array.elements[intern->array.size], elem);
656656
intern->array.size++;
657657
} else {
658658
Z_TRY_ADDREF_P(elem);
@@ -833,7 +833,7 @@ PHP_METHOD(SplFixedArray, offsetGet)
833833
value = spl_fixedarray_object_read_dimension_helper(intern, zindex);
834834

835835
if (value) {
836-
RETURN_COPY_DEREF(value);
836+
RETURN_COPY(value);
837837
} else {
838838
RETURN_NULL();
839839
}

ext/spl/tests/gh20614.phpt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
GH-20614 (SplFixedArray incorrectly handles references in deserialization)
3+
--FILE--
4+
<?php
5+
6+
$fa = new SplFixedArray(0);
7+
$nr = 1;
8+
$array = [&$nr];
9+
$fa->__unserialize($array);
10+
var_dump($fa);
11+
unset($fa[0]);
12+
var_dump($fa);
13+
14+
?>
15+
--EXPECT--
16+
object(SplFixedArray)#1 (1) {
17+
[0]=>
18+
int(1)
19+
}
20+
object(SplFixedArray)#1 (1) {
21+
[0]=>
22+
NULL
23+
}

0 commit comments

Comments
 (0)