From 427abf02c81071c5d3d31efacf09db22662dd82c Mon Sep 17 00:00:00 2001 From: ocfox Date: Mon, 13 Feb 2023 13:55:50 +0800 Subject: [PATCH] Fix potential integer overflow issue in wasm-c-api (#1954) Fix potential integer overflow issue in wasm-c-api reported by CodeQL --- core/iwasm/common/wasm_c_api.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/iwasm/common/wasm_c_api.c b/core/iwasm/common/wasm_c_api.c index 2b29330a..325f231d 100644 --- a/core/iwasm/common/wasm_c_api.c +++ b/core/iwasm/common/wasm_c_api.c @@ -4205,7 +4205,8 @@ wasm_memory_data_size(const wasm_memory_t *memory) (WASMModuleInstance *)module_inst_comm; WASMMemoryInstance *memory_inst = module_inst->memories[memory->memory_idx_rt]; - return memory_inst->cur_page_count * memory_inst->num_bytes_per_page; + return (size_t)memory_inst->cur_page_count + * memory_inst->num_bytes_per_page; } #endif @@ -4215,7 +4216,8 @@ wasm_memory_data_size(const wasm_memory_t *memory) AOTMemoryInstance *memory_inst = ((AOTMemoryInstance **) module_inst->memories)[memory->memory_idx_rt]; - return memory_inst->cur_page_count * memory_inst->num_bytes_per_page; + return (size_t)memory_inst->cur_page_count + * memory_inst->num_bytes_per_page; } #endif