Update type validation in load_table_import() and load_table() (#4296)

Prevent from value type.

https://webassembly.github.io/spec/core/valid/types.html#table-types
https://webassembly.github.io/gc/core/syntax/types.html#reference-types
This commit is contained in:
liang.he 2025-06-12 15:01:42 +08:00 committed by GitHub
parent 5478d267f4
commit 75bf9797a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2588,7 +2588,8 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end,
error_buf_size)) { error_buf_size)) {
return false; return false;
} }
if (wasm_is_reftype_htref_non_nullable(ref_type.ref_type)) { if (!wasm_is_type_reftype(ref_type.ref_type)
|| wasm_is_reftype_htref_non_nullable(ref_type.ref_type)) {
set_error_buf(error_buf, error_buf_size, "type mismatch"); set_error_buf(error_buf, error_buf_size, "type mismatch");
return false; return false;
} }
@ -3114,6 +3115,15 @@ load_table(const uint8 **p_buf, const uint8 *buf_end, WASMModule *module,
error_buf_size)) { error_buf_size)) {
return false; return false;
} }
/*
* TODO: add this validator
* `wasm_is_reftype_htref_non_nullable(ref_type.ref_type)`
* after sync up with the latest GC spec
*/
if (!wasm_is_type_reftype(ref_type.ref_type)) {
set_error_buf(error_buf, error_buf_size, "type mismatch");
return false;
}
table->table_type.elem_type = ref_type.ref_type; table->table_type.elem_type = ref_type.ref_type;
if (need_ref_type_map) { if (need_ref_type_map) {
if (!(table->table_type.elem_ref_type = if (!(table->table_type.elem_ref_type =