From c72add6a8242d0529f31eb0e1739ab56231d580e Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Fri, 6 Sep 2024 12:31:06 +0200 Subject: [PATCH] Disallow enums in ArrayObject --- ext/spl/spl_array.c | 6 ++++++ ext/spl/tests/ArrayObject_enum.phpt | 15 +++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 ext/spl/tests/ArrayObject_enum.phpt diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index dbe110f7c40da..b6d99f727703d 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -1091,6 +1091,12 @@ static void spl_array_set_array(zval *object, spl_array_object *intern, zval *ar ZSTR_VAL(Z_OBJCE_P(array)->name), ZSTR_VAL(intern->std.ce->name)); return; } + if (UNEXPECTED(Z_OBJCE_P(array)->ce_flags & ZEND_ACC_ENUM)) { + zend_throw_exception_ex(spl_ce_InvalidArgumentException, 0, + "Enum %s is not compatible with %s", + ZSTR_VAL(Z_OBJCE_P(array)->name), ZSTR_VAL(intern->std.ce->name)); + return; + } zval_ptr_dtor(&intern->array); ZVAL_COPY(&intern->array, array); } diff --git a/ext/spl/tests/ArrayObject_enum.phpt b/ext/spl/tests/ArrayObject_enum.phpt new file mode 100644 index 0000000000000..10c8a3d71e58a --- /dev/null +++ b/ext/spl/tests/ArrayObject_enum.phpt @@ -0,0 +1,15 @@ +--TEST-- +Enums are not compatible with ArrayObject +--FILE-- + +--EXPECTF-- +Fatal error: Uncaught InvalidArgumentException: Enum Foo is not compatible with ArrayObject in %s:%d +%a