Skip to content

Commit d61ff7c

Browse files
authored
ext/spl: ArrayObject no longer accepts arbitrary Iterators during unserialization (#22090)
This aligns the behaviour with the constructor of ArrayObject.
1 parent 625f0a7 commit d61ff7c

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

ext/spl/spl_array.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,9 +1482,9 @@ PHP_METHOD(ArrayObject, __unserialize)
14821482
RETURN_THROWS();
14831483
}
14841484

1485-
if (!instanceof_function(ce, zend_ce_iterator)) {
1485+
if (!instanceof_function(ce, spl_ce_ArrayIterator)) {
14861486
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
1487-
"Cannot deserialize ArrayObject with iterator class '%s'; this class does not implement the Iterator interface",
1487+
"Cannot deserialize ArrayObject with iterator class '%s'; this class is not derived from ArrayIterator",
14881488
ZSTR_VAL(Z_STR_P(iterator_class_zv)));
14891489
RETURN_THROWS();
14901490
}

ext/spl/tests/GH-22047.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
GH-22047: ArrayObject invalid iterator class in serialized payload
3+
--FILE--
4+
<?php
5+
6+
$payload = 'O:11:"ArrayObject":4:{i:0;i:0;i:1;a:2:{i:4;d:0.0;i:1;b:1;}i:2;a:0:{}i:3;s:12:"GlobIterator";}';
7+
8+
try {
9+
$obj = unserialize($payload);
10+
foreach ($obj as $k => $v) {
11+
echo "should not reach here\n";
12+
}
13+
} catch (UnexpectedValueException $e) {
14+
echo $e->getMessage(), "\n";
15+
}
16+
17+
?>
18+
--EXPECTF--
19+
Cannot deserialize ArrayObject with iterator class 'GlobIterator'; this class is not derived from ArrayIterator

ext/spl/tests/unserialize_errors.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Incomplete or ill-typed serialization data
144144
Passed variable is not an array or object
145145
Incomplete or ill-typed serialization data
146146
Cannot deserialize ArrayObject with iterator class 'NonExistent'; no such class exists
147-
Cannot deserialize ArrayObject with iterator class 'Existent'; this class does not implement the Iterator interface
147+
Cannot deserialize ArrayObject with iterator class 'Existent'; this class is not derived from ArrayIterator
148148
ArrayIterator:
149149
Incomplete or ill-typed serialization data
150150
Incomplete or ill-typed serialization data

0 commit comments

Comments
 (0)