Skip to content

Commit 1848bcd

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix phpGH-20614: SplFixedArray incorrectly handles references in deserialization
2 parents 157864a + 6afe2ce commit 1848bcd

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
@@ -635,7 +635,7 @@ PHP_METHOD(SplFixedArray, __unserialize)
635635
intern->array.size = 0;
636636
ZEND_HASH_FOREACH_STR_KEY_VAL(data, key, elem) {
637637
if (key == NULL) {
638-
ZVAL_COPY(&intern->array.elements[intern->array.size], elem);
638+
ZVAL_COPY_DEREF(&intern->array.elements[intern->array.size], elem);
639639
intern->array.size++;
640640
} else {
641641
Z_TRY_ADDREF_P(elem);
@@ -822,7 +822,7 @@ PHP_METHOD(SplFixedArray, offsetGet)
822822
value = spl_fixedarray_object_read_dimension_helper(intern, zindex);
823823

824824
if (value) {
825-
RETURN_COPY_DEREF(value);
825+
RETURN_COPY(value);
826826
} else {
827827
RETURN_NULL();
828828
}

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)