Skip to content

Fix GH-13531: Unable to resize SplfixedArray after being unserialized in PHP 8.2.15 #13543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ext/spl/spl_fixedarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static void spl_fixedarray_default_ctor(spl_fixedarray *array)
{
array->size = 0;
array->elements = NULL;
array->cached_resize = -1;
}

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

static void spl_fixedarray_init(spl_fixedarray *array, zend_long size)
Expand All @@ -120,7 +122,6 @@ static void spl_fixedarray_init(spl_fixedarray *array, zend_long size)
} else {
spl_fixedarray_default_ctor(array);
}
array->cached_resize = -1;
}

/* Copies the range [begin, end) into the fixedarray, beginning at `offset`.
Expand Down
28 changes: 28 additions & 0 deletions ext/spl/tests/gh13531.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--TEST--
GH-13531 (Unable to resize SplfixedArray after being unserialized in PHP 8.2.15)
--FILE--
<?php

$array = new SplFixedArray(5);
$array[4] = 1;
$serialized = serialize($array);
$unserialized = unserialize($serialized);
$unserialized->setSize(6);
var_dump($unserialized);

?>
--EXPECT--
object(SplFixedArray)#2 (6) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
[3]=>
NULL
[4]=>
int(1)
[5]=>
NULL
}