Skip to content

Commit

Permalink
Rollup merge of rust-lang#50634 - tbu-:pr_preadwrite_emscripten, r=ke…
Browse files Browse the repository at this point in the history
…nnytm

Do not silently truncate offsets for `read_at`/`write_at` on emscripten

Generate an IO error if the offset is out of bounds for the system call.
  • Loading branch information
alexcrichton authored May 11, 2018
2 parents a5cf9c1 + d71625b commit 1b9faa8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/libstd/sys/unix/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ impl FileDesc {
-> io::Result<isize>
{
use libc::pread64;
cvt(pread64(fd, buf, count, offset as i32))
// pread64 on emscripten actually takes a 32 bit offset
if let Ok(o) = offset.try_into() {
cvt(pread64(fd, buf, count, o))
} else {
Err(io::Error::new(io::ErrorKind::InvalidInput,
"cannot pread >2GB"))
}
}

#[cfg(not(any(target_os = "android", target_os = "emscripten")))]
Expand Down Expand Up @@ -117,7 +123,13 @@ impl FileDesc {
-> io::Result<isize>
{
use libc::pwrite64;
cvt(pwrite64(fd, buf, count, offset as i32))
// pwrite64 on emscripten actually takes a 32 bit offset
if let Ok(o) = offset.try_into() {
cvt(pwrite64(fd, buf, count, o))
} else {
Err(io::Error::new(io::ErrorKind::InvalidInput,
"cannot pwrite >2GB"))
}
}

#[cfg(not(any(target_os = "android", target_os = "emscripten")))]
Expand Down

0 comments on commit 1b9faa8

Please sign in to comment.