Skip to content

Commit 9774ced

Browse files
committed
Fix GH-15918: Assertion failure in ext/spl/spl_fixedarray.c
SplFixedArray should've never get supported in ArrayObject because it's overloaded, and so that breaks assumptions. This regressed in c4ecd82. Closes GH-15947.
1 parent c76913f commit 9774ced

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ PHP NEWS
1616
. Fixed bug GH-15711 (SoapClient can't convert BackedEnum to scalar value).
1717
(nielsdos)
1818

19+
- SPL:
20+
. Fixed bug GH-15918 (Assertion failure in ext/spl/spl_fixedarray.c).
21+
(nielsdos)
22+
1923
12 Sep 2024, PHP 8.3.12
2024

2125
- Core:

ext/spl/spl_array.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar
10841084
}
10851085
} else {
10861086
zend_object_get_properties_t handler = Z_OBJ_HANDLER_P(array, get_properties);
1087-
if (handler != zend_std_get_properties) {
1087+
if (handler != zend_std_get_properties || Z_OBJ_HANDLER_P(array, get_properties_for)) {
10881088
zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0,
10891089
"Overloaded object of type %s is not compatible with %s",
10901090
ZSTR_VAL(Z_OBJCE_P(array)->name), ZSTR_VAL(intern->std.ce->name));
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
11
--TEST--
2-
SplFixedArray properties is compatible with ArrayObject
2+
SplFixedArray properties is incompatible with ArrayObject
33
--FILE--
44
<?php
55
$ao = new ArrayObject([1, 2, 3]);
66
$fixedArray = new SplFixedArray(1);
77
$fixedArray[0] = new SplDoublyLinkedList();
8-
$ao->exchangeArray($fixedArray);
9-
$ao[0] = new stdClass();
10-
var_dump($ao);
8+
try {
9+
// See GH-15918: this *should* fail to not break invariants
10+
$ao->exchangeArray($fixedArray);
11+
} catch (InvalidArgumentException $e) {
12+
echo $e->getMessage(), "\n";
13+
}
1114
?>
1215
--EXPECT--
13-
object(ArrayObject)#1 (1) {
14-
["storage":"ArrayObject":private]=>
15-
object(SplFixedArray)#2 (2) {
16-
[0]=>
17-
object(SplDoublyLinkedList)#3 (2) {
18-
["flags":"SplDoublyLinkedList":private]=>
19-
int(0)
20-
["dllist":"SplDoublyLinkedList":private]=>
21-
array(0) {
22-
}
23-
}
24-
["0"]=>
25-
object(stdClass)#4 (0) {
26-
}
27-
}
28-
}
16+
Overloaded object of type SplFixedArray is not compatible with ArrayObject

ext/spl/tests/gh15918.phpt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
GH-15918 (Assertion failure in ext/spl/spl_fixedarray.c)
3+
--FILE--
4+
<?php
5+
$foo = new SplFixedArray(5);
6+
try {
7+
$arrayObject = new ArrayObject($foo);
8+
} catch (InvalidArgumentException $e) {
9+
echo $e->getMessage(), "\n";
10+
}
11+
?>
12+
--EXPECT--
13+
Overloaded object of type SplFixedArray is not compatible with ArrayObject

0 commit comments

Comments
 (0)