Skip to content

Commit 366ed4c

Browse files
committed
Fix phpGH-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. Closes phpGH-20616.
1 parent 4312a44 commit 366ed4c

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ PHP NEWS
6161
. Fixed ZPP type violation in phpdbg_get_executable() and phpdbg_end_oplog().
6262
(Girgias)
6363

64+
- SPL:
65+
. Fixed bug GH-20614 (SplFixedArray incorrectly handles references
66+
in deserialization). (ndossche)
67+
6468
- Standard:
6569
. Fix memory leak in array_diff() with custom type checks. (ndossche)
6670
. Fixed bug GH-20583 (Stack overflow in http_build_query

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)