Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,8 @@ PHP NEWS
table). (evankford)

- SPL:
. Fixed use-after-free when a destructor of an element of the old array
accesses the ArrayObject during ArrayObject::unserialize(). (Roman Ondráček)
. Fixed bug GH-24264 (Unwind/GracefulExit discarded in spl_iterators.c).
(Lazizbek Ergashev)

Expand Down
4 changes: 3 additions & 1 deletion ext/spl/spl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1342,10 +1342,12 @@ PHP_METHOD(ArrayObject, unserialize)
intern->ar_flags |= flags & SPL_ARRAY_CLONE_MASK;

if (Z_TYPE_P(array) == IS_ARRAY) {
zval_ptr_dtor(&intern->array);
zval garbage;
ZVAL_COPY_VALUE(&garbage, &intern->array);
ZVAL_COPY_VALUE(&intern->array, array);
ZVAL_NULL(array);
SEPARATE_ARRAY(&intern->array);
zval_ptr_dtor(&garbage);
} else {
spl_array_set_array(object, intern, array, 0L, 1);
}
Expand Down
19 changes: 19 additions & 0 deletions ext/spl/tests/ArrayObject_unserialize_release_order.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
ArrayObject::unserialize(): destructors of old elements do not observe the array being released
--FILE--
<?php
class D {
public function __destruct() {
global $ao;
$GLOBALS['keep'] = $ao->getArrayCopy();
}
}
$ao = new ArrayObject(['pad' => str_repeat('A', 64), 'd' => new D, 'pad2' => str_repeat('B', 64)]);
$ao->unserialize((new ArrayObject([1]))->serialize());
var_dump($keep);
?>
--EXPECT--
array(1) {
[0]=>
int(1)
}
Loading