Skip to content

Fix GH-15918: Assertion failure in ext/spl/spl_fixedarray.c #15947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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: 1 addition & 1 deletion ext/spl/spl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar
}
} else {
zend_object_get_properties_t handler = Z_OBJ_HANDLER_P(array, get_properties);
if (handler != zend_std_get_properties) {
if (handler != zend_std_get_properties || Z_OBJ_HANDLER_P(array, get_properties_for)) {
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0,
"Overloaded object of type %s is not compatible with %s",
ZSTR_VAL(Z_OBJCE_P(array)->name), ZSTR_VAL(intern->std.ce->name));
Expand Down
28 changes: 8 additions & 20 deletions ext/spl/tests/ArrayObject_overloaded_SplFixedArray.phpt
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
--TEST--
SplFixedArray properties is compatible with ArrayObject
SplFixedArray properties is incompatible with ArrayObject
--FILE--
<?php
$ao = new ArrayObject([1, 2, 3]);
$fixedArray = new SplFixedArray(1);
$fixedArray[0] = new SplDoublyLinkedList();
$ao->exchangeArray($fixedArray);
$ao[0] = new stdClass();
var_dump($ao);
try {
// See GH-15918: this *should* fail to not break invariants
$ao->exchangeArray($fixedArray);
} catch (InvalidArgumentException $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
object(ArrayObject)#1 (1) {
["storage":"ArrayObject":private]=>
object(SplFixedArray)#2 (2) {
[0]=>
object(SplDoublyLinkedList)#3 (2) {
["flags":"SplDoublyLinkedList":private]=>
int(0)
["dllist":"SplDoublyLinkedList":private]=>
array(0) {
}
}
["0"]=>
object(stdClass)#4 (0) {
}
}
}
Overloaded object of type SplFixedArray is not compatible with ArrayObject
13 changes: 13 additions & 0 deletions ext/spl/tests/gh15918.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
GH-15918 (Assertion failure in ext/spl/spl_fixedarray.c)
--FILE--
<?php
$foo = new SplFixedArray(5);
try {
$arrayObject = new ArrayObject($foo);
} catch (InvalidArgumentException $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Overloaded object of type SplFixedArray is not compatible with ArrayObject
Loading