loader: fix a potential overflow issue (#4427)

This commit is contained in:
Zhenwei Jin 2025-06-30 12:57:57 +08:00 committed by GitHub
parent 7a6a6a39e9
commit 0127eafbe5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -2042,9 +2042,9 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
"recursive type count too large");
return false;
}
module->type_count += rec_count - 1;
new_total_size =
sizeof(WASMFuncType *) * (uint64)module->type_count;
sizeof(WASMFuncType *)
* (uint64)(module->type_count + rec_count - 1);
if (new_total_size > UINT32_MAX) {
set_error_buf(error_buf, error_buf_size,
"allocate memory failed");
@ -2052,6 +2052,7 @@ load_type_section(const uint8 *buf, const uint8 *buf_end, WASMModule *module,
}
MEM_REALLOC(module->types, (uint32)total_size,
(uint32)new_total_size);
module->type_count += rec_count - 1;
total_size = new_total_size;
}