Skip to content

Commit 6154aa6

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

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
@@ -28,6 +28,10 @@ PHP NEWS
2828
- PCRE:
2929
. Fixed bug #81424 (PCRE2 10.35 JIT performance regression). (cmb)
3030

31+
- SPL:
32+
. Fixed bug #80663 (Recursive SplFixedArray::setSize() may cause double-free).
33+
(cmb, Nikita, Tyson Andre)
34+
3135
- XML:
3236
. Fixed bug #70962 (XML_OPTION_SKIP_WHITE strips embedded whitespace).
3337
(Aliaksandr Bystry, cmb)

ext/spl/spl_fixedarray.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,14 @@ static void spl_fixedarray_dtor_range(spl_fixedarray *array, zend_long from, zen
149149
*/
150150
static void spl_fixedarray_dtor(spl_fixedarray *array)
151151
{
152-
zend_long size = array->size;
153152
if (!spl_fixedarray_empty(array)) {
154-
spl_fixedarray_dtor_range(array, 0, size);
155-
efree(array->elements);
153+
zval *begin = array->elements, *end = array->elements + array->size;
154+
array->elements = NULL;
155+
array->size = 0;
156+
while (begin != end) {
157+
zval_ptr_dtor(--end);
158+
}
159+
efree(begin);
156160
}
157161
}
158162

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)