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();