Skip to content

Commit f9cd3b8

Browse files
committed
validate heap_type in load_import_table_list
Signed-off-by: zhenweijin <zhenwei.jin@intel.com>
1 parent d7459e8 commit f9cd3b8

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

core/iwasm/aot/aot_loader.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
#include "../common/wasm_native.h"
1111
#include "../common/wasm_loader_common.h"
1212
#include "../compilation/aot.h"
13+
#if WASM_ENABLE_GC != 0
14+
#include "../common/gc/gc_type.h"
15+
#endif
1316
#if WASM_ENABLE_AOT_VALIDATOR != 0
1417
#include "aot_validator.h"
1518
#endif
@@ -1474,7 +1477,24 @@ load_import_table_list(const uint8 **p_buf, const uint8 *buf_end,
14741477
read_uint32(buf, buf_end, ref_type.ref_ht_common.heap_type);
14751478

14761479
ref_type.ref_type = import_table->table_type.elem_type;
1477-
/* TODO: check ref_type */
1480+
/* Validate heap_type: must be a valid type index or common heap type */
1481+
if (ref_type.ref_ht_common.heap_type >= 0) {
1482+
/* type index must be less than type_count */
1483+
if ((uint32)ref_type.ref_ht_common.heap_type
1484+
>= module->type_count) {
1485+
set_error_buf(error_buf, error_buf_size,
1486+
"unknown type: type index out of range");
1487+
return false;
1488+
}
1489+
}
1490+
else {
1491+
/* common heap type must be valid */
1492+
if (!wasm_is_valid_heap_type(ref_type.ref_ht_common.heap_type)) {
1493+
set_error_buf(error_buf, error_buf_size,
1494+
"unknown type: invalid heap type");
1495+
return false;
1496+
}
1497+
}
14781498
if (!(import_table->table_type.elem_ref_type =
14791499
wasm_reftype_set_insert(module->ref_type_set,
14801500
&ref_type))) {

0 commit comments

Comments
 (0)