@@ -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))) {
@@ -3957,6 +3967,11 @@ load_function_section(const uint8 *buf, const uint8 *buf_end,
39573967 }
39583968#if WASM_ENABLE_GC != 0
39593969 if (ref_type_map_count > 0) {
3970+ if (ref_type_map_count > UINT16_MAX) {
3971+ set_error_buf(error_buf, error_buf_size,
3972+ "ref type count too large");
3973+ return false;
3974+ }
39603975 total_size =
39613976 sizeof(WASMRefTypeMap) * (uint64)ref_type_map_count;
39623977 if (!(func->local_ref_type_maps = loader_malloc(
0 commit comments