Skip to content

Commit 794a35c

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: ext/spl: Fix SplFixedArray::setSize leak when destructor grows during clear.
2 parents 28f668d + 86250c0 commit 794a35c

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
@@ -170,18 +170,18 @@ static void spl_fixedarray_resize(spl_fixedarray *array, zend_long size)
170170
return;
171171
}
172172

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

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