Skip to content

Commit 857ed91

Browse files
committed
fix potential overflow in memory size calculation
Signed-off-by: zhenweijin <[email protected]>
1 parent 6b51c61 commit 857ed91

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

core/iwasm/interpreter/wasm_runtime.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,14 @@ memory_instantiate(WASMModuleInstance *module_inst, WASMModuleInstance *parent,
335335
/* If only one page and at most one page, we just append
336336
the app heap to the end of linear memory, enlarge the
337337
num_bytes_per_page, and don't change the page count */
338-
heap_offset = num_bytes_per_page;
339-
num_bytes_per_page += heap_size;
340-
if (num_bytes_per_page < heap_size) {
338+
if (heap_size > UINT32_MAX - num_bytes_per_page) {
341339
set_error_buf(error_buf, error_buf_size,
342340
"failed to insert app heap into linear memory, "
343341
"try using `--heap-size=0` option");
344342
return NULL;
345343
}
344+
heap_offset = num_bytes_per_page;
345+
num_bytes_per_page += heap_size;
346346
}
347347
else if (heap_size > 0) {
348348
if (init_page_count == max_page_count && init_page_count == 0) {

0 commit comments

Comments
 (0)