Skip to content

Commit e73cc7a

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix #80663: Recursive SplFixedArray::setSize() may cause double-free
2 parents d0715aa + 6154aa6 commit e73cc7a

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ PHP NEWS
1111
ReflectionClass). (Nikita)
1212
. Fixed bug #81474 (Make ReflectionEnum and related class non-final). (Nikita)
1313

14+
- SPL:
15+
. Fixed bug #80663 (Recursive SplFixedArray::setSize() may cause double-free).
16+
(cmb, Nikita, Tyson Andre)
17+
1418
- XML:
1519
. Fixed bug #70962 (XML_OPTION_SKIP_WHITE strips embedded whitespace).
1620
(Aliaksandr Bystry, cmb)

ext/spl/spl_fixedarray.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,14 @@ static void spl_fixedarray_dtor_range(spl_fixedarray *array, zend_long from, zen
156156
*/
157157
static void spl_fixedarray_dtor(spl_fixedarray *array)
158158
{
159-
zend_long size = array->size;
160159
if (!spl_fixedarray_empty(array)) {
161-
spl_fixedarray_dtor_range(array, 0, size);
162-
efree(array->elements);
160+
zval *begin = array->elements, *end = array->elements + array->size;
161+
array->elements = NULL;
162+
array->size = 0;
163+
while (begin != end) {
164+
zval_ptr_dtor(--end);
165+
}
166+
efree(begin);
163167
}
164168
}
165169

ext/spl/tests/bug80663.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #80663 (Recursive SplFixedArray::setSize() may cause double-free)
3+
--FILE--
4+
<?php
5+
class InvalidDestructor {
6+
public function __destruct() {
7+
$GLOBALS['obj']->setSize(0);
8+
}
9+
}
10+
11+
$obj = new SplFixedArray(1000);
12+
$obj[0] = new InvalidDestructor();
13+
$obj->setSize(0);
14+
?>
15+
--EXPECT--

0 commit comments

Comments
 (0)