From d21bc7f1e66e897a4acef27ca363e6bbeb606485 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 Closes GH-15775 --- UPGRADING | 4 ++++ ext/spl/spl_array.c | 6 ++++++ ext/spl/tests/ArrayObject_enum.phpt | 15 +++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 ext/spl/tests/ArrayObject_enum.phpt diff --git a/UPGRADING b/UPGRADING index 88f66696cb4..c9c9468a3bd 100644 --- a/UPGRADING +++ b/UPGRADING @@ -19,6 +19,10 @@ PHP 8.5 UPGRADE NOTES 1. Backward Incompatible Changes ======================================== +- SPL: + . ArrayObject no longer accepts enums, as modifying the $name or $value + properties can break engine assumptions. + ======================================== 2. New Features ======================================== diff --git a/ext/spl/spl_array.c b/ext/spl/spl_array.c index 0be317c173e..ffe8178afa7 100644 --- a/ext/spl/spl_array.c +++ b/ext/spl/spl_array.c @@ -970,6 +970,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, + "Enums are not compatible with %s", + 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 00000000000..906c89b54df --- /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: Enums are not compatible with ArrayObject in %s:%d +%a