-
Notifications
You must be signed in to change notification settings - Fork 698
Prevent potential overflow #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?
Conversation
PR bytecodealliance#4300 introduced the rationale for validating heap_type. This patch moves the validation before the computation of type1 to prevent potential overflow.
Further improved the heap type check logic:
|
goto fail; | ||
} | ||
type1 = (uint8)((int32)0x80 + heap_type); | ||
} |
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.
better have a comment @l867 to hint that if heap_type < 0
, if (!is_byte_a_type(type1) || wasm_is_type_multi_byte_type(type1))
will be false.
goto fail; | ||
} | ||
type1 = (uint8)((int32)0x80 + heap_type); | ||
} |
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.
Another suggestion is to merge those if...else..
blocks, like:
if (heap_type >= 0) {
if (!check_type_index(module, module->type_count, heap_type,
error_buf, error_buf_size)) {
goto fail;
}
wasm_set_refheaptype_typeidx(&cur_ref_type.ref_ht_typeidx,
true, heap_type);
if (!push_const_expr_stack(&const_expr_ctx, flag,
cur_ref_type.ref_type,
&cur_ref_type, 0, &cur_value,
error_buf, error_buf_size))
goto fail;
}
else {
if (!wasm_is_valid_heap_type(heap_type)) {
set_error_buf_v(error_buf, error_buf_size,
"unknown type %d", heap_type);
goto fail;
}
type1 = (uint8)((int32)0x80 + heap_type);
if (!push_const_expr_stack(&const_expr_ctx, flag, type1,
NULL, 0, &cur_value, error_buf,
error_buf_size))
goto fail;
}
PR #4300 introduced the rationale for validating heap_type.
This patch moves the validation before the computation of type1 to prevent potential overflow.