Skip to content

Commit 7a9cfd5

Browse files
committed
Fix memory corruption when unpacking unknown enum
1 parent 621c1e9 commit 7a9cfd5

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

msgpack_unpack.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,26 @@ int msgpack_unserialize_map_item(msgpack_unpack_data *unpack, zval **container,
692692
__FUNCTION__, Z_STRVAL_P(key));
693693
#else
694694
ce = msgpack_unserialize_class(container, Z_STR_P(key), 0);
695+
/* Enums are not allowed to implement Serializable nor __unserialize */
696+
if (ce == NULL || ce == PHP_IC_ENTRY) {
697+
MSGPACK_WARNING(
698+
"[msgpack] (%s) Enum definition %s could not be loaded",
699+
__FUNCTION__, Z_STRVAL_P(key));
700+
701+
MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val);
702+
return 0;
703+
}
704+
705+
/* found class is not an Enum but a normal Class */
706+
if (!(ce->ce_flags & ZEND_ACC_ENUM)) {
707+
MSGPACK_WARNING(
708+
"[msgpack] (%s) Class %s is expected to be an Enum",
709+
__FUNCTION__, ZSTR_VAL(ce->name));
710+
711+
MSGPACK_UNSERIALIZE_FINISH_MAP_ITEM(unpack, key, val);
712+
return 0;
713+
}
714+
695715
zend_object *enum_instance = zend_enum_get_case(ce, Z_STR_P(val));
696716
ZVAL_OBJ(*container, enum_instance);
697717
#endif

0 commit comments

Comments
 (0)