From ace919129986dd9dd3965bd56ba900d49b093775 Mon Sep 17 00:00:00 2001 From: Sergey Pepyakin Date: Mon, 29 Jan 2018 17:15:01 +0300 Subject: [PATCH] MemoryAccessOutOfBounds for mem get and set. --- src/runner.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/runner.rs b/src/runner.rs index 3aec783..739b3ec 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -543,7 +543,8 @@ impl<'a, E: Externals> Interpreter<'a, E> { let m = context.module() .memory_by_index(DEFAULT_MEMORY_INDEX) .expect("Due to validation memory should exists"); - let b = m.get(address, mem::size_of::())?; + let b = m.get(address, mem::size_of::()) + .map_err(|_| Error::Trap(Trap::MemoryAccessOutOfBounds))?; let n = T::from_little_endian(&b)?; context.value_stack_mut().push(n.into())?; Ok(InstructionOutcome::RunNextInstruction) @@ -560,7 +561,8 @@ impl<'a, E: Externals> Interpreter<'a, E> { let m = context.module() .memory_by_index(DEFAULT_MEMORY_INDEX) .expect("Due to validation memory should exists"); - let b = m.get(address, mem::size_of::())?; + let b = m.get(address, mem::size_of::()) + .map_err(|_| Error::Trap(Trap::MemoryAccessOutOfBounds))?; let v = T::from_little_endian(&b)?; let stack_value: U = v.extend_into(); context @@ -586,7 +588,8 @@ impl<'a, E: Externals> Interpreter<'a, E> { let m = context.module() .memory_by_index(DEFAULT_MEMORY_INDEX) .expect("Due to validation memory should exists"); - m.set(address, &stack_value)?; + m.set(address, &stack_value) + .map_err(|_| Error::Trap(Trap::MemoryAccessOutOfBounds))?; Ok(InstructionOutcome::RunNextInstruction) } @@ -616,7 +619,8 @@ impl<'a, E: Externals> Interpreter<'a, E> { let m = context.module() .memory_by_index(DEFAULT_MEMORY_INDEX) .expect("Due to validation memory should exists"); - m.set(address, &stack_value)?; + m.set(address, &stack_value) + .map_err(|_| Error::Trap(Trap::MemoryAccessOutOfBounds))?; Ok(InstructionOutcome::RunNextInstruction) }