Skip to content

Commit 0127eaf

Browse files
authored
loader: fix a potential overflow issue (#4427)
1 parent 7a6a6a3 commit 0127eaf

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

core/iwasm/interpreter/wasm_loader.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,16 +2042,17 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
20422042
"recursive type count too large");
20432043
return false;
20442044
}
2045-
module->type_count += rec_count - 1;
20462045
new_total_size =
2047-
sizeof(WASMFuncType *) * (uint64)module->type_count;
2046+
sizeof(WASMFuncType *)
2047+
* (uint64)(module->type_count + rec_count - 1);
20482048
if (new_total_size > UINT32_MAX) {
20492049
set_error_buf(error_buf, error_buf_size,
20502050
"allocate memory failed");
20512051
return false;
20522052
}
20532053
MEM_REALLOC(module->types, (uint32)total_size,
20542054
(uint32)new_total_size);
2055+
module->type_count += rec_count - 1;
20552056
total_size = new_total_size;
20562057
}
20572058

0 commit comments

Comments
 (0)