Skip to content

Commit 69ea2d8

Browse files
committed
Convert check + exception to assertion
Move the inside the __unserialize() method as that's the only one which now needs this check Closes GH-8207
1 parent 0ba9216 commit 69ea2d8

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

ext/spl/spl_array.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -993,11 +993,9 @@ static HashTable *spl_array_it_get_gc(zend_object_iterator *iter, zval **table,
993993
}
994994

995995
/* {{{ spl_array_set_array */
996-
static void spl_array_set_array(zval *object, spl_array_object *intern, zval *array, zend_long ar_flags, int just_array) {
997-
if (Z_TYPE_P(array) != IS_OBJECT && Z_TYPE_P(array) != IS_ARRAY) {
998-
zend_throw_exception(spl_ce_InvalidArgumentException, "Passed variable is not an array or object", 0);
999-
return;
1000-
}
996+
static void spl_array_set_array(zval *object, spl_array_object *intern, zval *array, zend_long ar_flags, bool just_array) {
997+
/* Handled by ZPP prior to this, or for __unserialize() before passing to here */
998+
ZEND_ASSERT(Z_TYPE_P(array) == IS_ARRAY || Z_TYPE_P(array) == IS_OBJECT);
1001999
if (Z_TYPE_P(array) == IS_ARRAY) {
10021000
zval_ptr_dtor(&intern->array);
10031001
if (Z_REFCOUNT_P(array) == 1) {
@@ -1739,6 +1737,11 @@ PHP_METHOD(ArrayObject, __unserialize)
17391737
zval_ptr_dtor(&intern->array);
17401738
ZVAL_UNDEF(&intern->array);
17411739
} else {
1740+
if (Z_TYPE_P(storage_zv) != IS_OBJECT && Z_TYPE_P(storage_zv) != IS_ARRAY) {
1741+
/* TODO Use UnexpectedValueException instead? And better error message? */
1742+
zend_throw_exception(spl_ce_InvalidArgumentException, "Passed variable is not an array or object", 0);
1743+
RETURN_THROWS();
1744+
}
17421745
spl_array_set_array(ZEND_THIS, intern, storage_zv, 0L, 1);
17431746
}
17441747

0 commit comments

Comments
 (0)