Skip to content

Commit 753645a

Browse files
committed
Merge remote-tracking branch 'origin/PHP-7.4' into PHP-8.0
2 parents 5d702e3 + b053192 commit 753645a

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

ext/spl/spl_fixedarray.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,12 @@ static void spl_fixedarray_object_write_dimension_helper(spl_fixedarray_object *
368368
zend_throw_exception(spl_ce_RuntimeException, "Index invalid or out of range", 0);
369369
return;
370370
} else {
371-
zval_ptr_dtor(&(intern->array.elements[index]));
372-
ZVAL_COPY_DEREF(&intern->array.elements[index], value);
371+
/* Fix #81429 */
372+
zval *ptr = &(intern->array.elements[index]);
373+
zval tmp;
374+
ZVAL_COPY_VALUE(&tmp, ptr);
375+
ZVAL_COPY_DEREF(ptr, value);
376+
zval_ptr_dtor(&tmp);
373377
}
374378
}
375379

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
--TEST--
2+
SplFixedArray::setSize in offsetSet destructor (#81429)
3+
--FILE--
4+
<?php
5+
$values = new SplFixedArray(1);
6+
$values->offsetSet(0, new HasDestructor());
7+
$values->offsetSet(0, false);
8+
echo "Done\n";
9+
10+
class HasDestructor {
11+
public function __destruct() {
12+
global $values;
13+
var_dump($values);
14+
$values->setSize($values->getSize() - 1);
15+
var_dump($values);
16+
}
17+
}
18+
19+
$values->setSize(5);
20+
$values->offsetSet(4, new HasDestructor());
21+
echo "Done\n";
22+
--EXPECT--
23+
object(SplFixedArray)#1 (1) {
24+
[0]=>
25+
bool(false)
26+
}
27+
object(SplFixedArray)#1 (1) {
28+
[0]=>
29+
bool(false)
30+
}
31+
Done
32+
Done
33+
object(SplFixedArray)#1 (5) {
34+
[0]=>
35+
NULL
36+
[1]=>
37+
NULL
38+
[2]=>
39+
NULL
40+
[3]=>
41+
NULL
42+
[4]=>
43+
object(HasDestructor)#2 (0) {
44+
}
45+
}
46+
object(SplFixedArray)#1 (4) {
47+
[0]=>
48+
NULL
49+
[1]=>
50+
NULL
51+
[2]=>
52+
NULL
53+
[3]=>
54+
NULL
55+
}

0 commit comments

Comments
 (0)