Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

sys/miri: fix `Mmap::from_file` to seek to start of file. (#12572)

Chris Fallin362350195708
diff --git a/crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs b/crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs
index 3e3145886f..1afbc44f33 100644
--- a/crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs
+++ b/crates/wasmtime/src/runtime/vm/sys/miri/mmap.rs
@@ -10,7 +10,7 @@ use crate::runtime::vm::sys::vm::MemoryImageSource;
use crate::runtime::vm::{HostAlignedByteCount, SendSyncPtr};
use std::alloc::{self, Layout};
use std::fs::File;
-use std::io::Read;
+use std::io::{Read, Seek, SeekFrom};
use std::ops::Range;
use std::path::Path;
use std::ptr::NonNull;
@@ -63,6 +63,7 @@ impl Mmap {
// Read the file and copy it in to a fresh "mmap" to have allocation for
// an mmap only in one location.
let mut dst = Vec::new();
+ file.seek(SeekFrom::Start(0))?;
file.read_to_end(&mut dst)?;
let count = HostAlignedByteCount::new_rounded_up(dst.len())?;
let result = Mmap::new(count)?;