diff --git a/crates/wasmtime/src/runtime/vm/mmap.rs b/crates/wasmtime/src/runtime/vm/mmap.rs index f06bb0a8d436..3a7b57dbf890 100644 --- a/crates/wasmtime/src/runtime/vm/mmap.rs +++ b/crates/wasmtime/src/runtime/vm/mmap.rs @@ -137,7 +137,7 @@ impl Mmap { /// /// Returns an error if `offset >= self.len_aligned()`. pub fn offset(self: &Arc, offset: HostAlignedByteCount) -> Result { - if offset >= self.len_aligned() { + if offset > self.len_aligned() { bail!( "offset {} is not in bounds for mmap: {}", offset, @@ -363,7 +363,7 @@ impl MmapOffset { // end of the mmap. We may need to change this if that becomes // necessary. assert!( - offset < mmap.len_aligned(), + offset <= mmap.len_aligned(), "offset {} is in bounds (< {})", offset, mmap.len_aligned(), diff --git a/tests/all/memory.rs b/tests/all/memory.rs index 6c8f1c651924..fb46d40d0d36 100644 --- a/tests/all/memory.rs +++ b/tests/all/memory.rs @@ -734,3 +734,19 @@ fn get_memory_type_with_custom_page_size_from_wasm(config: &mut Config) -> Resul Ok(()) } + +#[wasmtime_test] +fn configure_zero(config: &mut Config) -> Result<()> { + config.guard_before_linear_memory(false); + config.memory_guard_size(0); + config.memory_reservation(0); + config.memory_reservation_for_growth(0); + let engine = Engine::new(&config)?; + let mut store = Store::new(&engine, ()); + + let ty = MemoryType::new(0, None); + let memory = Memory::new(&mut store, ty)?; + assert_eq!(memory.data_size(&store), 0); + + Ok(()) +}