diff --git a/crates/lightbeam/src/module.rs b/crates/lightbeam/src/module.rs index 9e93cec5ba..02cb9c09ec 100644 --- a/crates/lightbeam/src/module.rs +++ b/crates/lightbeam/src/module.rs @@ -7,7 +7,7 @@ use cranelift_codegen::{ isa, }; use memoffset::offset_of; -use more_asserts::assert_le; + use std::{convert::TryInto, mem}; use thiserror::Error; use wasmparser::{FuncType, MemoryType, ModuleReader, SectionCode, Type}; @@ -563,15 +563,19 @@ pub fn translate_only(data: &[u8]) -> Result { let memories = section.get_memory_section_reader()?; let mem = translate_sections::memory(memories)?; - assert_le!( - mem.len(), - 1, - "Multiple memory sections not yet unimplemented" - ); + if mem.len() > 1 { + return Err(Error::Input( + "Multiple memory sections not yet implemented".to_string(), + )); + } if !mem.is_empty() { let mem = mem[0]; - assert_eq!(Some(mem.limits.initial), mem.limits.maximum); + if Some(mem.limits.initial) != mem.limits.maximum { + return Err(Error::Input( + "Custom memory limits not supported in lightbeam".to_string(), + )); + } output.memory = Some(mem); } @@ -642,7 +646,11 @@ pub fn translate_only(data: &[u8]) -> Result { translate_sections::data(data)?; } - assert!(reader.eof()); + if !reader.eof() { + return Err(Error::Input( + "Unexpected data found after the end of the module".to_string(), + )); + } Ok(output) }