Skip to content

Commit e8ce0d0

Browse files
committed
add bounds checking to prevent ref_type_map_count
Signed-off-by: zhenweijin <[email protected]>
1 parent 6b51c61 commit e8ce0d0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

core/iwasm/interpreter/wasm_loader.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,11 @@ resolve_func_type(const uint8 **p_buf, const uint8 *buf_end, WASMModule *module,
17991799
return false;
18001800
}
18011801
if (ref_type_map_count > 0) {
1802+
if (ref_type_map_count > UINT16_MAX) {
1803+
set_error_buf(error_buf, error_buf_size,
1804+
"ref type count too large");
1805+
return false;
1806+
}
18021807
total_size = sizeof(WASMRefTypeMap) * (uint64)ref_type_map_count;
18031808
if (!(type->ref_type_maps =
18041809
loader_malloc(total_size, error_buf, error_buf_size))) {
@@ -1938,6 +1943,11 @@ resolve_struct_type(const uint8 **p_buf, const uint8 *buf_end,
19381943
return false;
19391944
}
19401945
if (ref_type_map_count > 0) {
1946+
if (ref_type_map_count > UINT16_MAX) {
1947+
set_error_buf(error_buf, error_buf_size,
1948+
"ref type count too large");
1949+
return false;
1950+
}
19411951
total_size = sizeof(WASMRefTypeMap) * (uint64)ref_type_map_count;
19421952
if (!(type->ref_type_maps =
19431953
loader_malloc(total_size, error_buf, error_buf_size))) {
@@ -3953,6 +3963,11 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
39533963
}
39543964
#if WASM_ENABLE_GC != 0
39553965
if (ref_type_map_count > 0) {
3966+
if (ref_type_map_count > UINT16_MAX) {
3967+
set_error_buf(error_buf, error_buf_size,
3968+
"ref type count too large");
3969+
return false;
3970+
}
39563971
total_size =
39573972
sizeof(WASMRefTypeMap) * (uint64)ref_type_map_count;
39583973
if (!(func->local_ref_type_maps = loader_malloc(

0 commit comments

Comments
 (0)