From 148f2b446a33fa3f84f30bb4e51a09579e91ca4a Mon Sep 17 00:00:00 2001 From: Dan Burkert Date: Wed, 19 Sep 2018 22:23:46 -0700 Subject: [PATCH] PoC: possible repro for issue 69 --- src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 5010c005..5603dd21 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1005,4 +1005,27 @@ mod test { let mmap = mmap.make_exec().expect("make_exec"); drop(mmap); } + + #[test] + fn issue69() { + let tempdir = tempdir::TempDir::new("mmap").unwrap(); + let path = tempdir.path().join("mmap"); + + // Create a 3GiB (sparse) file. + let file = OpenOptions::new() + .read(true) + .write(true) + .create(true) + .open(&path) + .unwrap(); + let len = 3 * 1024 * 1024 * 1024; + file.set_len(len).unwrap(); + + // Map the file. + let mmap = unsafe { MmapOptions::new().map_mut(&file).unwrap() }; + + // All bytes should be 0, and the slice length should match. + assert_eq!(mmap[..].len() as u64, len); + assert!(mmap[..].iter().all(|&byte| byte == 0)); + } }