From 5f8d1428d5d95aec12e0fddecb54c8aafb9dc61a Mon Sep 17 00:00:00 2001 From: YoungWenMing <35167225+YoungWenMing@users.noreply.github.com> Date: Sat, 23 Apr 2022 17:38:11 +0800 Subject: [PATCH] wasm_runtime.c: Fix fault modification on data segment (#1116) Fix fault modification on data segment in wasm module which leads to fail to instantiate wasm module next time, reported by #1115. Co-authored-by: yangwenming --- core/iwasm/interpreter/wasm_runtime.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/iwasm/interpreter/wasm_runtime.c b/core/iwasm/interpreter/wasm_runtime.c index c6aa2da2..49051b10 100644 --- a/core/iwasm/interpreter/wasm_runtime.c +++ b/core/iwasm/interpreter/wasm_runtime.c @@ -1333,12 +1333,14 @@ wasm_instantiate(WASMModule *module, bool is_sub_inst, uint32 stack_size, goto fail; } - data_seg->base_offset.u.i32 = + base_offset = globals[data_seg->base_offset.u.global_index].initial_value.i32; } + else { + base_offset = (uint32)data_seg->base_offset.u.i32; + } /* check offset */ - base_offset = (uint32)data_seg->base_offset.u.i32; if (base_offset > memory_size) { LOG_DEBUG("base_offset(%d) > memory_size(%d)", base_offset, memory_size);