Skip to content

Commit

Permalink
Safely handle offset in fd_seek
Browse files Browse the repository at this point in the history
This commit fixes [#4556][1].  Passing in a negative offset along with
`whence::set` causes wasmer to erroneously seek to a very large offset.

[1]: #4556
  • Loading branch information
yagehu authored and theduke committed Apr 12, 2024
1 parent fe3c6d0 commit c3f2887
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/wasix/src/syscalls/wasi/fd_seek.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ pub(crate) fn fd_seek_internal(
Whence::Set => {
let mut fd_map = state.fs.fd_map.write().unwrap();
let fd_entry = wasi_try_ok_ok!(fd_map.get_mut(&fd).ok_or(Errno::Badf));
fd_entry.offset.store(offset as u64, Ordering::Release);
offset as u64
let offset: u64 = wasi_try_ok_ok!(u64::try_from(offset).map_err(|_| Errno::Inval));

fd_entry.offset.store(offset, Ordering::Release);
offset
}
_ => return Ok(Err(Errno::Inval)),
};
Expand Down

0 comments on commit c3f2887

Please sign in to comment.