From 26c8c704b3afc18cd22254c752180dd88a1bf20c Mon Sep 17 00:00:00 2001 From: Andreas Wahlen Date: Mon, 31 Aug 2026 20:55:49 +0200 Subject: [PATCH] Follow up fix for #186 --- msgpack_unpack.c | 27 +++------------------------ tests/issue186.2.phpt | 2 +- tests/issue186.3.phpt | 2 +- tests/issue186.4.phpt | 27 +++++++++++++++++++++++++++ 4 files changed, 32 insertions(+), 26 deletions(-) create mode 100644 tests/issue186.4.phpt diff --git a/msgpack_unpack.c b/msgpack_unpack.c index 2db95b7..b946532 100644 --- a/msgpack_unpack.c +++ b/msgpack_unpack.c @@ -723,10 +723,10 @@ int msgpack_unserialize_map_item(msgpack_unpack_data *unpack, zval **container, } /* found Enum does not contain specified case */ - zend_class_constant *constant_ptr = zend_hash_find_ptr( - &ce->constants_table, + zend_class_constant *constant = zend_hash_find_ptr( + CE_CONSTANTS_TABLE(ce), Z_STR_P(val)); - if (constant_ptr == NULL) { + if (constant == NULL || !(ZEND_CLASS_CONST_FLAGS(constant) & ZEND_CLASS_CONST_IS_CASE)) { MSGPACK_WARNING( "[msgpack] (%s) Enum case %s does not exist in Enum %s", __FUNCTION__, Z_STRVAL_P(val), ZSTR_VAL(ce->name)); @@ -735,27 +735,6 @@ int msgpack_unserialize_map_item(msgpack_unpack_data *unpack, zval **container, return 0; } - /* found Enum property is not a case but a constant */ - zval *constant = &constant_ptr->value; - if (Z_TYPE_P(constant) == IS_OBJECT) { - zend_object *obj = Z_OBJ_P(constant); - if (!instanceof_function(obj->ce, ce)) { - MSGPACK_WARNING( - "[msgpack] (%s) %s::%s is not an Enum case but a constant", - __FUNCTION__, ZSTR_VAL(ce->name), Z_STRVAL_P(val)); - - MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); - return 0; - } - } else { - MSGPACK_WARNING( - "[msgpack] (%s) %s::%s is not an Enum case but a constant", - __FUNCTION__, ZSTR_VAL(ce->name), Z_STRVAL_P(val)); - - MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val); - return 0; - } - zend_object *enum_instance = zend_enum_get_case(ce, Z_STR_P(val)); ZVAL_OBJ_COPY(*container, enum_instance); #endif diff --git a/tests/issue186.2.phpt b/tests/issue186.2.phpt index d5723de..3e02e51 100644 --- a/tests/issue186.2.phpt +++ b/tests/issue186.2.phpt @@ -26,5 +26,5 @@ OK --EXPECTF-- Test -Warning: [msgpack] (msgpack_unserialize_map_item) TestEnum::B is not an Enum case but a constant in %s/issue186.2.php on line 11 +Warning: [msgpack] (msgpack_unserialize_map_item) Enum case B does not exist in Enum TestEnum in %s/issue186.2.php on line 11 OK diff --git a/tests/issue186.3.phpt b/tests/issue186.3.phpt index 8b44cce..610d8c8 100644 --- a/tests/issue186.3.phpt +++ b/tests/issue186.3.phpt @@ -30,5 +30,5 @@ OK --EXPECTF-- Test -Warning: [msgpack] (msgpack_unserialize_map_item) TestEnum::B is not an Enum case but a constant in %s/issue186.3.php on line 15 +Warning: [msgpack] (msgpack_unserialize_map_item) Enum case B does not exist in Enum TestEnum in %s/issue186.3.php on line 15 OK diff --git a/tests/issue186.4.phpt b/tests/issue186.4.phpt new file mode 100644 index 0000000..caac4bd --- /dev/null +++ b/tests/issue186.4.phpt @@ -0,0 +1,27 @@ +--TEST-- +Issue #182 (unknown enum case) +--SKIPIF-- + +--FILE-- +Test + +OK +--EXPECTF-- +Test +OK