-
Notifications
You must be signed in to change notification settings - Fork 704
improve logic of heap_type
validation when ref.null
#4372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
fd5cfe4
66cd7f6
d0aac00
58aae86
038e2fc
0020653
17ac8c1
f297e08
54bed47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -830,32 +830,49 @@ load_init_expr(WASMModule *module, const uint8 **p_buf, const uint8 *buf_end, | |
case INIT_EXPR_TYPE_REFNULL_CONST: | ||
{ | ||
uint8 type1; | ||
|
||
#if WASM_ENABLE_GC == 0 | ||
#if WASM_ENABLE_GC != 0 | ||
const uint8 *p_copy = p; | ||
int32 heap_type; | ||
read_leb_int32(p_copy, p_end, heap_type); | ||
#endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another thing, L872 will read it again. Seems we can remove either one. |
||
CHECK_BUF(p, p_end, 1); | ||
type1 = read_uint8(p); | ||
|
||
#if WASM_ENABLE_GC == 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. like above, in L839, rename |
||
cur_value.ref_index = NULL_REF; | ||
if (!push_const_expr_stack(&const_expr_ctx, flag, type1, | ||
&cur_value, error_buf, | ||
error_buf_size)) | ||
goto fail; | ||
#else | ||
int32 heap_type; | ||
read_leb_int32(p, p_end, heap_type); | ||
type1 = (uint8)((int32)0x80 + heap_type); | ||
|
||
cur_value.gc_obj = NULL_REF; | ||
|
||
/* | ||
* According to the current GC SPEC rules, the heap_type must be | ||
* validated when ref.null is used. It can be an absheaptype, | ||
* or the type C.types[typeidx] must be defined in the context. | ||
*/ | ||
if (heap_type >= 0) { | ||
if (!check_type_index(module, module->type_count, heap_type, | ||
error_buf, error_buf_size)) { | ||
goto fail; | ||
} | ||
} | ||
else { | ||
if (!wasm_is_valid_heap_type(heap_type)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Guess There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Likewise, considering the same code context in function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But in this case, not reusing exactly the same code. Maybe it's possible by just copying the content from |
||
set_error_buf_v(error_buf, error_buf_size, | ||
"unknown type %d", heap_type); | ||
goto fail; | ||
} | ||
} | ||
Septa2112 marked this conversation as resolved.
Show resolved
Hide resolved
Septa2112 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. after |
||
if (!is_byte_a_type(type1) | ||
|| !wasm_is_valid_heap_type(heap_type) | ||
|| wasm_is_type_multi_byte_type(type1)) { | ||
p--; | ||
read_leb_uint32(p, p_end, type_idx); | ||
if (!check_type_index(module, module->type_count, type_idx, | ||
error_buf, error_buf_size)) | ||
goto fail; | ||
|
||
wasm_set_refheaptype_typeidx(&cur_ref_type.ref_ht_typeidx, | ||
true, type_idx); | ||
if (!push_const_expr_stack(&const_expr_ctx, flag, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If following the spec, s33 should be a type index. might rename it as type_index better.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might not be appropriate to rename
heap_type
totype_idx
here:type_idx
has already been defined as auint32
at the beginning of this function.wasm_loader_prepare_bytecode
whenWASM_OP_REF_NULL
, I think it's clearer and more consistent to keep the nameheap_type
.wasm-micro-runtime/core/iwasm/interpreter/wasm_loader.c
Lines 13154 to 13169 in 18d4227
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this
case
, there is also a variable namedtype1
, which is a bad name. Keeping two variables with unclear meanings will make the code difficult to understand.