Skip to content

Commit 80b1527

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

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

core/iwasm/aot/aot_loader.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
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
16+
1317
#if WASM_ENABLE_AOT_VALIDATOR != 0
1418
#include "aot_validator.h"
1519
#endif
@@ -1474,7 +1478,26 @@ load_import_table_list(const uint8 **p_buf, const uint8 *buf_end,
14741478
read_uint32(buf, buf_end, ref_type.ref_ht_common.heap_type);
14751479

14761480
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+
}
14781501
if (!(import_table->table_type.elem_ref_type =
14791502
wasm_reftype_set_insert(module->ref_type_set,
14801503
&ref_type))) {

0 commit comments

Comments
 (0)