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
4 changes: 2 additions & 2 deletions ext/spl/spl_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -1482,9 +1482,9 @@ PHP_METHOD(ArrayObject, __unserialize)
RETURN_THROWS();
}

if (!instanceof_function(ce, zend_ce_iterator)) {
if (!instanceof_function(ce, spl_ce_ArrayIterator)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more restrictive than the current code. But then I have no idea if it even makes sens to attempt to use any iterator. But in this case the error message needs to be fixed.

Copy link
Copy Markdown
Contributor Author

@arshidkv12 arshidkv12 May 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.
Please check the following code.

$arrayObject = new ArrayObject(
    [
        4 => 0.0,
        1 => true
    ],
    0,
    "GlobIterator"
);

var_dump( $arrayObject);

Output:

Fatal error: Uncaught TypeError: ArrayObject::__construct(): Argument #3 ($iteratorClass) must be a class name derived from ArrayIterator, GlobIterator given in /Users/arshid/Downloads/php-src/z.php:20
Stack trace:
#0 /Users/arshid/Downloads/php-src/z.php(20): ArrayObject->__construct(Array, 0, 'GlobIterator')
#1 {main}
  thrown in /Users/arshid/Downloads/php-src/z.php on line 20

https://github.com/php/php-src/blob/master/Zend/zend_API.c#L1001

scr

zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
"Cannot deserialize ArrayObject with iterator class '%s'; this class does not implement the Iterator interface",
"Cannot deserialize ArrayObject with iterator class '%s'; this class is not derived from ArrayIterator",
ZSTR_VAL(Z_STR_P(iterator_class_zv)));
RETURN_THROWS();
}
Expand Down
19 changes: 19 additions & 0 deletions ext/spl/tests/GH-22047.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
GH-22047: ArrayObject invalid iterator class in serialized payload
--FILE--
<?php

$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";}';

try {
$obj = unserialize($payload);
foreach ($obj as $k => $v) {
echo "should not reach here\n";
}
} catch (UnexpectedValueException $e) {
echo $e->getMessage(), "\n";
}

?>
--EXPECTF--
Cannot deserialize ArrayObject with iterator class 'GlobIterator'; this class is not derived from ArrayIterator
2 changes: 1 addition & 1 deletion ext/spl/tests/unserialize_errors.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Incomplete or ill-typed serialization data
Passed variable is not an array or object
Incomplete or ill-typed serialization data
Cannot deserialize ArrayObject with iterator class 'NonExistent'; no such class exists
Cannot deserialize ArrayObject with iterator class 'Existent'; this class does not implement the Iterator interface
Cannot deserialize ArrayObject with iterator class 'Existent'; this class is not derived from ArrayIterator
ArrayIterator:
Incomplete or ill-typed serialization data
Incomplete or ill-typed serialization data
Expand Down
Loading