Skip to content

Commit 86250c0

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: ext/spl: Fix SplFixedArray::setSize leak when destructor grows during clear.
2 parents cf7b509 + cb3dc62 commit 86250c0

2 files changed

Lines changed: 34 additions & 6 deletions

File tree

ext/spl/spl_fixedarray.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,18 @@ static void spl_fixedarray_resize(spl_fixedarray *array, zend_long size)
172172
return;
173173
}
174174

175-
/* first initialization */
176-
if (array->size == 0) {
177-
spl_fixedarray_init(array, size);
178-
return;
179-
}
180-
181175
if (UNEXPECTED(array->cached_resize >= 0)) {
182176
/* We're already resizing, so just remember the desired size.
183177
* The resize will happen later. */
184178
array->cached_resize = size;
185179
return;
186180
}
181+
/* first initialization */
182+
if (array->size == 0) {
183+
spl_fixedarray_init(array, size);
184+
return;
185+
}
186+
187187
array->cached_resize = size;
188188

189189
/* clearing the array */
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
SplFixedArray::setSize: grow re-entrantly during clear (setSize(0))
3+
--FILE--
4+
<?php
5+
class Reentrant {
6+
public ?SplFixedArray $arr = null;
7+
public function __destruct() {
8+
if ($this->arr !== null) {
9+
$this->arr->setSize(5);
10+
}
11+
}
12+
}
13+
14+
$arr = new SplFixedArray(2);
15+
$r = new Reentrant();
16+
$r->arr = $arr;
17+
$arr[0] = $r;
18+
unset($r);
19+
$arr[1] = "tail";
20+
21+
$arr->setSize(0);
22+
echo "size: ", $arr->getSize(), "\n";
23+
$arr[0] = "ok";
24+
var_dump($arr[0]);
25+
?>
26+
--EXPECT--
27+
size: 5
28+
string(2) "ok"

0 commit comments

Comments
 (0)