Skip to content
This repository has been archived by the owner on Nov 9, 2019. It is now read-only.

Commit

Permalink
Add an overflow check
Browse files Browse the repository at this point in the history
The check will be removed when rust-lang/rust#63326 is fixed
  • Loading branch information
marmistrz committed Aug 8, 2019
1 parent c95d217 commit 48cf790
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/hostcalls_impl/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ pub(crate) fn fd_allocate(

let current_size = metadata.len();
let wanted_size = offset.checked_add(len).ok_or(host::__WASI_E2BIG)?;
// This check will be unnecessary when rust-lang/rust#63326 is fixed
if wanted_size > i64::max_value() as u64 {
return Err(host::__WASI_E2BIG);
}
Expand Down Expand Up @@ -779,6 +780,10 @@ pub(crate) fn fd_filestat_set_size(
.and_then(|fe| fe.fd_object.descriptor.as_file())?;

let st_size = dec_filesize(st_size);
// This check will be unnecessary when rust-lang/rust#63326 is fixed
if st_size > i64::max_value() as u64 {
return Err(host::__WASI_E2BIG);
}
fd.set_len(st_size).map_err(errno_from_ioerror)
}

Expand Down

0 comments on commit 48cf790

Please sign in to comment.