Просмотр исходного кода

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
liang.he 7 месяцев назад
Родитель
Сommit
75bf9797a2
1 измененных файлов с 11 добавлено и 1 удалено
  1. 11 1
      core/iwasm/interpreter/wasm_loader.c

+ 11 - 1
core/iwasm/interpreter/wasm_loader.c

@@ -2588,7 +2588,8 @@ load_table_import(const uint8 **p_buf, const uint8 *buf_end,
                             error_buf_size)) {
         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");
         return false;
     }
@@ -3114,6 +3115,15 @@ load_table(const uint8 **p_buf, const uint8 *buf_end, WASMModule *module,
                             error_buf_size)) {
         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;
     if (need_ref_type_map) {
         if (!(table->table_type.elem_ref_type =