Skip to content

Commit 22015f0

Browse files
committed
fix(zend): deep-copy nested type lists when erasing a generic bound
not sure if this is the right fix here.. Signed-off-by: azjezz <azjezz@protonmail.com>
1 parent a52ce5f commit 22015f0

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

Zend/zend_compile.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8051,6 +8051,22 @@ ZEND_API void zend_set_function_arg_flags(zend_function *func) /* {{{ */
80518051
}
80528052
/* }}} */
80538053

8054+
static zend_type_list *zend_arena_deep_copy_type_list(zend_type_list *src)
8055+
{
8056+
size_t list_size = ZEND_TYPE_LIST_SIZE(src->num_types);
8057+
zend_type_list *copy = zend_arena_alloc(&CG(arena), list_size);
8058+
memcpy(copy, src, list_size);
8059+
for (uint32_t i = 0; i < copy->num_types; i++) {
8060+
if (ZEND_TYPE_HAS_LIST(copy->types[i])) {
8061+
ZEND_TYPE_SET_PTR(copy->types[i], zend_arena_deep_copy_type_list(ZEND_TYPE_LIST(copy->types[i])));
8062+
} else if (ZEND_TYPE_HAS_NAME(copy->types[i])) {
8063+
zend_string_addref(ZEND_TYPE_NAME(copy->types[i]));
8064+
}
8065+
}
8066+
8067+
return copy;
8068+
}
8069+
80548070
static zend_type zend_compile_single_typename(zend_ast *ast)
80558071
{
80568072
ZEND_ASSERT(!(ast->attr & ZEND_TYPE_NULLABLE));
@@ -8088,17 +8104,9 @@ static zend_type zend_compile_single_typename(zend_ast *ast)
80888104
if (ZEND_TYPE_HAS_NAME(result)) {
80898105
zend_string_addref(ZEND_TYPE_NAME(result));
80908106
} else if (ZEND_TYPE_HAS_LIST(result)) {
8091-
zend_type_list *orig_list = ZEND_TYPE_LIST(result);
8092-
size_t list_size = ZEND_TYPE_LIST_SIZE(orig_list->num_types);
8093-
zend_type_list *copy = zend_arena_alloc(&CG(arena), list_size);
8094-
memcpy(copy, orig_list, list_size);
8095-
for (uint32_t i = 0; i < copy->num_types; i++) {
8096-
if (ZEND_TYPE_HAS_NAME(copy->types[i])) {
8097-
zend_string_addref(ZEND_TYPE_NAME(copy->types[i]));
8098-
}
8099-
}
8100-
ZEND_TYPE_SET_PTR(result, copy);
8107+
ZEND_TYPE_SET_PTR(result, zend_arena_deep_copy_type_list(ZEND_TYPE_LIST(result)));
81018108
}
8109+
81028110
return result;
81038111
}
81048112

0 commit comments

Comments
 (0)