From a7ba70307ba89c117649da94eec49e518d2c6fc7 Mon Sep 17 00:00:00 2001 From: Arshia Ghafoori Date: Thu, 9 May 2024 23:08:45 +0330 Subject: [PATCH] Account for stack_lower being above stack_higher --- lib/wasix/src/state/func_env.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/wasix/src/state/func_env.rs b/lib/wasix/src/state/func_env.rs index 280e156071a..0934c95ec41 100644 --- a/lib/wasix/src/state/func_env.rs +++ b/lib/wasix/src/state/func_env.rs @@ -183,7 +183,7 @@ impl WasiFunctionEnv { )); } - let stack_lower = if let Some(stack_low) = stack_low { + let mut stack_lower = if let Some(stack_low) = stack_low { match stack_low.get(store) { wasmer::Value::I32(a) => a as u64, wasmer::Value::I64(a) => a as u64, @@ -203,6 +203,14 @@ impl WasiFunctionEnv { 0 }; + if stack_lower >= stack_base { + tracing::warn!( + "Detected lower end of stack to be above higher end, ignoring stack_lower; \ + unwinding may cause memory corruption" + ); + stack_lower = 0; + } + // Update the stack layout which is need for asyncify let env = self.data_mut(store); let tid = env.tid();