Skip to content

Commit 1d20fc5

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix GH-13531: Unable to resize SplfixedArray after being unserialized in PHP 8.2.15
2 parents 6f258f0 + 0285395 commit 1d20fc5

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

ext/spl/spl_fixedarray.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ static void spl_fixedarray_default_ctor(spl_fixedarray *array)
8989
{
9090
array->size = 0;
9191
array->elements = NULL;
92+
array->cached_resize = -1;
9293
}
9394

9495
/* Initializes the range [from, to) to null. Does not dtor existing elements. */
@@ -107,6 +108,7 @@ static void spl_fixedarray_init_non_empty_struct(spl_fixedarray *array, zend_lon
107108
array->size = 0; /* reset size in case ecalloc() fails */
108109
array->elements = size ? safe_emalloc(size, sizeof(zval), 0) : NULL;
109110
array->size = size;
111+
array->cached_resize = -1;
110112
}
111113

112114
static void spl_fixedarray_init(spl_fixedarray *array, zend_long size)
@@ -117,7 +119,6 @@ static void spl_fixedarray_init(spl_fixedarray *array, zend_long size)
117119
} else {
118120
spl_fixedarray_default_ctor(array);
119121
}
120-
array->cached_resize = -1;
121122
}
122123

123124
/* Copies the range [begin, end) into the fixedarray, beginning at `offset`.

ext/spl/tests/gh13531.phpt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
GH-13531 (Unable to resize SplfixedArray after being unserialized in PHP 8.2.15)
3+
--FILE--
4+
<?php
5+
6+
$array = new SplFixedArray(5);
7+
$array[4] = 1;
8+
$serialized = serialize($array);
9+
$unserialized = unserialize($serialized);
10+
$unserialized->setSize(6);
11+
var_dump($unserialized);
12+
13+
?>
14+
--EXPECT--
15+
object(SplFixedArray)#2 (6) {
16+
[0]=>
17+
NULL
18+
[1]=>
19+
NULL
20+
[2]=>
21+
NULL
22+
[3]=>
23+
NULL
24+
[4]=>
25+
int(1)
26+
[5]=>
27+
NULL
28+
}

0 commit comments

Comments
 (0)