Skip to content

Commit 9734ba4

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix phpGH-20614: SplFixedArray incorrectly handles references in deserialization
2 parents 1701589 + 366ed4c commit 9734ba4

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
@@ -65,6 +65,10 @@ PHP NEWS
6565
. Fixed ZPP type violation in phpdbg_get_executable() and phpdbg_end_oplog().
6666
(Girgias)
6767

68+
- SPL:
69+
. Fixed bug GH-20614 (SplFixedArray incorrectly handles references
70+
in deserialization). (ndossche)
71+
6872
- Standard:
6973
. Fix memory leak in array_diff() with custom type checks. (ndossche)
7074
. 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
@@ -645,7 +645,7 @@ PHP_METHOD(SplFixedArray, __unserialize)
645645
intern->array.size = 0;
646646
ZEND_HASH_FOREACH_STR_KEY_VAL(data, key, elem) {
647647
if (key == NULL) {
648-
ZVAL_COPY(&intern->array.elements[intern->array.size], elem);
648+
ZVAL_COPY_DEREF(&intern->array.elements[intern->array.size], elem);
649649
intern->array.size++;
650650
} else {
651651
Z_TRY_ADDREF_P(elem);
@@ -826,7 +826,7 @@ PHP_METHOD(SplFixedArray, offsetGet)
826826
value = spl_fixedarray_object_read_dimension_helper(intern, zindex);
827827

828828
if (value) {
829-
RETURN_COPY_DEREF(value);
829+
RETURN_COPY(value);
830830
} else {
831831
RETURN_NULL();
832832
}

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)