Skip to content

Commit 6afe2ce

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix phpGH-20614: SplFixedArray incorrectly handles references in deserialization
2 parents 227541c + 9734ba4 commit 6afe2ce

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
@@ -54,6 +54,10 @@ PHP NEWS
5454
. Fixed ZPP type violation in phpdbg_get_executable() and phpdbg_end_oplog().
5555
(Girgias)
5656

57+
- SPL:
58+
. Fixed bug GH-20614 (SplFixedArray incorrectly handles references
59+
in deserialization). (ndossche)
60+
5761
- Standard:
5862
. Fix memory leak in array_diff() with custom type checks. (ndossche)
5963
. 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
@@ -639,7 +639,7 @@ PHP_METHOD(SplFixedArray, __unserialize)
639639
intern->array.size = 0;
640640
ZEND_HASH_FOREACH_STR_KEY_VAL(data, key, elem) {
641641
if (key == NULL) {
642-
ZVAL_COPY(&intern->array.elements[intern->array.size], elem);
642+
ZVAL_COPY_DEREF(&intern->array.elements[intern->array.size], elem);
643643
intern->array.size++;
644644
} else {
645645
Z_TRY_ADDREF_P(elem);
@@ -832,7 +832,7 @@ PHP_METHOD(SplFixedArray, offsetGet)
832832
value = spl_fixedarray_object_read_dimension_helper(intern, zindex);
833833

834834
if (value) {
835-
RETURN_COPY_DEREF(value);
835+
RETURN_COPY(value);
836836
} else {
837837
RETURN_NULL();
838838
}

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)