|
10 | 10 | #include "../common/wasm_native.h" |
11 | 11 | #include "../common/wasm_loader_common.h" |
12 | 12 | #include "../compilation/aot.h" |
| 13 | +#if WASM_ENABLE_GC != 0 |
| 14 | +#include "../common/gc/gc_type.h" |
| 15 | +#endif |
| 16 | + |
13 | 17 | #if WASM_ENABLE_AOT_VALIDATOR != 0 |
14 | 18 | #include "aot_validator.h" |
15 | 19 | #endif |
@@ -1474,7 +1478,26 @@ load_import_table_list(const uint8 **p_buf, const uint8 *buf_end, |
1474 | 1478 | read_uint32(buf, buf_end, ref_type.ref_ht_common.heap_type); |
1475 | 1479 |
|
1476 | 1480 | ref_type.ref_type = import_table->table_type.elem_type; |
1477 | | - /* TODO: check ref_type */ |
| 1481 | + /* Validate heap_type: must be a valid type index or common heap |
| 1482 | + * type */ |
| 1483 | + if (ref_type.ref_ht_common.heap_type >= 0) { |
| 1484 | + /* type index must be less than type_count */ |
| 1485 | + if ((uint32)ref_type.ref_ht_common.heap_type |
| 1486 | + >= module->type_count) { |
| 1487 | + set_error_buf(error_buf, error_buf_size, |
| 1488 | + "unknown type: type index out of range"); |
| 1489 | + return false; |
| 1490 | + } |
| 1491 | + } |
| 1492 | + else { |
| 1493 | + /* common heap type must be valid */ |
| 1494 | + if (!wasm_is_valid_heap_type( |
| 1495 | + ref_type.ref_ht_common.heap_type)) { |
| 1496 | + set_error_buf(error_buf, error_buf_size, |
| 1497 | + "unknown type: invalid heap type"); |
| 1498 | + return false; |
| 1499 | + } |
| 1500 | + } |
1478 | 1501 | if (!(import_table->table_type.elem_ref_type = |
1479 | 1502 | wasm_reftype_set_insert(module->ref_type_set, |
1480 | 1503 | &ref_type))) { |
|
0 commit comments