Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 7 additions & 5 deletions ext/spl/spl_fixedarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static void spl_fixedarray_init(spl_fixedarray *array, zend_long size) /* {{{ */

static void spl_fixedarray_resize(spl_fixedarray *array, zend_long size) /* {{{ */
{
if (size == array->size) {
if (size == array->size || (size == 0 && array->elements == NULL)) {
/* nothing to do */
return;
}
Expand All @@ -107,14 +107,16 @@ static void spl_fixedarray_resize(spl_fixedarray *array, zend_long size) /* {{{
/* clearing the array */
if (size == 0) {
zend_long i;
zval *elements = array->elements;

array->elements = NULL;

for (i = 0; i < array->size; i++) {
zval_ptr_dtor(&(array->elements[i]));
zval_ptr_dtor(&(elements[i]));
}

if (array->elements) {
efree(array->elements);
array->elements = NULL;
if (elements) {
efree(elements);
}
} else if (size > array->size) {
array->elements = safe_erealloc(array->elements, size, sizeof(zval), 0);
Expand Down
20 changes: 20 additions & 0 deletions ext/spl/tests/bug80663.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
Bug #80663 (Recursive SplFixedArray::setSize() may cause double-free)
--FILE--
<?php
class InvalidDestructor {
public function __destruct() {
try {
$GLOBALS['obj']->setSize(0);
} catch (LogicException $ex) {
echo $ex->getMessage();
}
}
}

$obj = new SplFixedArray(1000);
$obj[0] = new InvalidDestructor();
$obj->setSize(0);
?>
--EXPECT--