Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Returning error if offset doesn't fit into libc::off_t. #86

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/unix.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
extern crate libc;

use std::convert::TryInto;
use std::fs::File;
use std::mem::ManuallyDrop;
use std::os::unix::io::{FromRawFd, RawFd};
Expand Down Expand Up @@ -45,7 +46,15 @@ impl MmapInner {
offset: u64,
) -> io::Result<MmapInner> {
let alignment = offset % page_size() as u64;
let aligned_offset = offset - alignment;
let aligned_offset: libc::off_t = (offset - alignment).try_into().map_err(|_| {
// On some platforms, libc exposed by rust uses 32 bit for file
// offset. In these cases, we can't honor requests for mappings
// starting from beyond the initial 4 GB.
io::Error::new(
io::ErrorKind::InvalidData,
"memory map offset overflows libc::off_t",
)
})?;

let (map_len, map_offset) = Self::adjust_mmap_params(len as usize, alignment as usize)?;

Expand All @@ -56,7 +65,7 @@ impl MmapInner {
prot,
flags,
file,
aligned_offset as libc::off_t,
aligned_offset,
);

if ptr == libc::MAP_FAILED {
Expand Down