Skip to content

Commit 816a47e

Browse files
committed
ext/spl: Fix ArrayObject unserialize validation for invalid iterator classes
1 parent 10dad92 commit 816a47e

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

ext/spl/spl_array.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,8 @@ 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) &&
1486+
!instanceof_function(ce, spl_ce_RecursiveArrayIterator)) {
14861487
zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
14871488
"Cannot deserialize ArrayObject with iterator class '%s'; this class does not implement the Iterator interface",
14881489
ZSTR_VAL(Z_STR_P(iterator_class_zv)));

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 does not implement the Iterator interface

0 commit comments

Comments
 (0)