mirror of
https://github.com/php/php-src.git
synced 2026-10-29 02:07:35 +08:00
ext/spl: Fix SplFixedArray::setSize leak when destructor grows during clear.
close GH-21920
This commit is contained in:
3 files changed
+38
-6
No files matched your search
@@ -9,6 +9,10 @@ PHP NEWS
|
||||
- OpenSSL:
|
||||
. Fix compatibility issues with OpenSSL 4.0. (jordikroon, Remi)
|
||||
|
||||
- SPL:
|
||||
. Fix SplFixedArray::setSize leak when destructor grows during clear.
|
||||
(David Carlier)
|
||||
|
||||
- Standard:
|
||||
. Fixed bug GH-21689 (version_compare() incorrectly handles versions ending
|
||||
with a dot). (timwolla)
|
||||
|
||||
@@ -172,18 +172,18 @@ static void spl_fixedarray_resize(spl_fixedarray *array, zend_long size)
|
||||
return;
|
||||
}
|
||||
|
||||
/* first initialization */
|
||||
if (array->size == 0) {
|
||||
spl_fixedarray_init(array, size);
|
||||
return;
|
||||
}
|
||||
|
||||
if (UNEXPECTED(array->cached_resize >= 0)) {
|
||||
/* We're already resizing, so just remember the desired size.
|
||||
* The resize will happen later. */
|
||||
array->cached_resize = size;
|
||||
return;
|
||||
}
|
||||
/* first initialization */
|
||||
if (array->size == 0) {
|
||||
spl_fixedarray_init(array, size);
|
||||
return;
|
||||
}
|
||||
|
||||
array->cached_resize = size;
|
||||
|
||||
/* clearing the array */
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
--TEST--
|
||||
SplFixedArray::setSize: grow re-entrantly during clear (setSize(0))
|
||||
--FILE--
|
||||
<?php
|
||||
class Reentrant {
|
||||
public ?SplFixedArray $arr = null;
|
||||
public function __destruct() {
|
||||
if ($this->arr !== null) {
|
||||
$this->arr->setSize(5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$arr = new SplFixedArray(2);
|
||||
$r = new Reentrant();
|
||||
$r->arr = $arr;
|
||||
$arr[0] = $r;
|
||||
unset($r);
|
||||
$arr[1] = "tail";
|
||||
|
||||
$arr->setSize(0);
|
||||
echo "size: ", $arr->getSize(), "\n";
|
||||
$arr[0] = "ok";
|
||||
var_dump($arr[0]);
|
||||
?>
|
||||
--EXPECT--
|
||||
size: 5
|
||||
string(2) "ok"
|
||||
Reference in new issue
Block a user