Skip to content

Commit

Permalink
Merge branch 'PHP-8.3'
Browse files Browse the repository at this point in the history
* PHP-8.3:
  Fix phpGH-13531: Unable to resize SplfixedArray after being unserialized in PHP 8.2.15
  • Loading branch information
nielsdos committed Feb 27, 2024
2 parents 6f258f0 + 0285395 commit 1d20fc5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ext/spl/spl_fixedarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,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 @@ -107,6 +108,7 @@ static void spl_fixedarray_init_non_empty_struct(spl_fixedarray *array, zend_lon
array->size = 0; /* reset size in case ecalloc() fails */
array->elements = size ? safe_emalloc(size, sizeof(zval), 0) : NULL;
array->size = size;
array->cached_resize = -1;
}

static void spl_fixedarray_init(spl_fixedarray *array, zend_long size)
Expand All @@ -117,7 +119,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
}

0 comments on commit 1d20fc5

Please sign in to comment.