From 05f3c5bdccb3d7c4229a40137dc28ccf4bb0b213 Mon Sep 17 00:00:00 2001 From: grandizzy <38490174+grandizzy@users.noreply.github.com> Date: Fri, 17 May 2024 12:20:47 +0300 Subject: [PATCH] fix(interpreter): avoid overflow when checking if mem limit reached (#1429) --- crates/interpreter/src/interpreter/shared_memory.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/interpreter/src/interpreter/shared_memory.rs b/crates/interpreter/src/interpreter/shared_memory.rs index e76015a58c..cc63e1bf07 100644 --- a/crates/interpreter/src/interpreter/shared_memory.rs +++ b/crates/interpreter/src/interpreter/shared_memory.rs @@ -90,7 +90,7 @@ impl SharedMemory { #[cfg(feature = "memory_limit")] #[inline] pub fn limit_reached(&self, new_size: usize) -> bool { - (self.last_checkpoint + new_size) as u64 > self.memory_limit + self.last_checkpoint.saturating_add(new_size) as u64 > self.memory_limit } /// Prepares the shared memory for a new context.