Skip to content

Commit 8494058

Browse files
committed
Fix GH-13531: Unable to resize SplfixedArray after being unserialized in PHP 8.2.15
When unserializing, the cached_resize field was not reset to -1 correctly, causing the setSize() method to think we were inside of a resize operation. Closes GH-13543.
1 parent 3d4b36f commit 8494058

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ PHP NEWS
55
- PDO:
66
. Fix various PDORow bugs. (Girgias)
77

8+
- SPL:
9+
. Fixed bug GH-13531 (Unable to resize SplfixedArray after being unserialized
10+
in PHP 8.2.15). (nielsdos)
11+
812
- XML:
913
. Fixed bug GH-13517 (Multiple test failures when building with
1014
--with-expat). (nielsdos)

ext/spl/spl_fixedarray.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ static void spl_fixedarray_default_ctor(spl_fixedarray *array)
9191
{
9292
array->size = 0;
9393
array->elements = NULL;
94+
array->cached_resize = -1;
9495
}
9596

9697
/* Initializes the range [from, to) to null. Does not dtor existing elements. */
@@ -110,6 +111,7 @@ static void spl_fixedarray_init_non_empty_struct(spl_fixedarray *array, zend_lon
110111
array->elements = size ? safe_emalloc(size, sizeof(zval), 0) : NULL;
111112
array->size = size;
112113
array->should_rebuild_properties = true;
114+
array->cached_resize = -1;
113115
}
114116

115117
static void spl_fixedarray_init(spl_fixedarray *array, zend_long size)
@@ -120,7 +122,6 @@ static void spl_fixedarray_init(spl_fixedarray *array, zend_long size)
120122
} else {
121123
spl_fixedarray_default_ctor(array);
122124
}
123-
array->cached_resize = -1;
124125
}
125126

126127
/* 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)