-
Notifications
You must be signed in to change notification settings - Fork 624
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
support gc opcode generated by binaryen #2110
support gc opcode generated by binaryen #2110
Conversation
if (dst_offset + len >= wasm_array_obj_length(dst_obj) | ||
|| src_offset + len | ||
>= wasm_array_obj_length(src_obj)) { |
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.
Integer overflow may happen in dst_offset + len
and src_offset + len
. And when len is 0, it should be allowed? Had better be like below?
if (len > 0) {
if (dst_offset + len > dst_offset
|| dst_offset + len >= wasm_array_obj_length(dst_obj)
|| src_offset + len > src_offset
|| src_offset + len >= wasm_array_obj_length(src_obj)) {
wasm_set_exception(module, "array index out of bounds");
goto got_exception;
}
wasm_array_obj_copy(dst_obj, dst_offset, src_obj,
src_offset, len);
}
HANDLE_OP_END();
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.
Thanks
Using dst_offset + len < dst_offset
to check overflow actually triggers an overflow, which is not guaranteed by C standard, so I changed the operand to uint64 and check if the result exceeds UINT32_MAX
wasm_set_exception(module, "null array object"); | ||
goto got_exception; | ||
} | ||
if (dst_offset + len >= wasm_array_obj_length(dst_obj) |
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.
Same as above
core/iwasm/interpreter/wasm_loader.c
Outdated
#if WASM_ENABLE_FAST_INTERP != 0 | ||
emit_uint32(loader_ctx, type_idx); | ||
#endif | ||
/* typeidx1 */ |
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.
typeidx2?
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.
Thanks, done
} | ||
|
||
if (len > 0) { | ||
if (((uint64)dst_offset + (uint64)len >= UINT32_MAX) |
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.
=
should be allowed. And how about checking it according to SDL rule:
len > UINT32_MAX - dst_offset
We used it in:
https://github.com/bytecodealliance/wasm-micro-runtime/blob/main/core/iwasm/common/wasm_memory.c#L277-L278
if (len > 0) { | ||
if (((uint64)dst_offset + (uint64)len >= UINT32_MAX) | ||
|| (dst_offset + len | ||
>= wasm_array_obj_length(dst_obj)) |
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.
>=
to >
? =
is allowed
if (((uint64)dst_offset + (uint64)len >= UINT32_MAX) | ||
|| (dst_offset + len | ||
>= wasm_array_obj_length(dst_obj)) | ||
|| ((uint64)src_offset + (uint64)len | ||
>= UINT32_MAX) | ||
|| (src_offset + len | ||
>= wasm_array_obj_length(src_obj))) { |
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.
Same as above
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.
LGTM
Support GC opcodes generated by binaryen (bytecodealliance#2110)
No description provided.