diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 1f9f87d35841..4577bf19017b 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -1482,7 +1482,7 @@ PHP_METHOD(ArrayObject, __unserialize) RETURN_THROWS(); } - if (!instanceof_function(ce, zend_ce_iterator)) { + if (!instanceof_function(ce, spl_ce_ArrayIterator)) { zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0, "Cannot deserialize ArrayObject with iterator class '%s'; this class does not implement the Iterator interface", ZSTR_VAL(Z_STR_P(iterator_class_zv))); diff --git a/ext/spl/tests/GH-22047.phpt b/ext/spl/tests/GH-22047.phpt new file mode 100644 index 000000000000..4eb849b491c6 --- /dev/null +++ b/ext/spl/tests/GH-22047.phpt @@ -0,0 +1,19 @@ +--TEST-- +GH-22047: ArrayObject invalid iterator class in serialized payload +--FILE-- + $v) { + echo "should not reach here\n"; + } +} catch (UnexpectedValueException $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECTF-- +Cannot deserialize ArrayObject with iterator class 'GlobIterator'; this class does not implement the Iterator interface