Browse Source

fd_seek: error with invalid offsets in the adapter

pull/6374/head
Pat Hickey 2 years ago
parent
commit
fddf6ca5aa
  1. 14
      src/lib.rs

14
src/lib.rs

@ -1109,12 +1109,16 @@ pub unsafe extern "C" fn fd_seek(
filesystem::DescriptorType::Directory => return Err(ERRNO_BADF),
_ => {}
}
// It's ok to cast these indices; the WASI API will fail if
// the resulting values are out of range.
let from = match whence {
WHENCE_SET => offset,
WHENCE_CUR => (file.position.get() as i64).wrapping_add(offset),
WHENCE_END => (filesystem::stat(file.fd)?.size as i64) + offset,
WHENCE_SET if offset >= 0 => offset,
WHENCE_CUR => match (file.position.get() as i64).checked_add(offset) {
Some(pos) if pos >= 0 => pos,
_ => return Err(ERRNO_INVAL),
},
WHENCE_END => match (filesystem::stat(file.fd)?.size as i64).checked_add(offset) {
Some(pos) if pos >= 0 => pos,
_ => return Err(ERRNO_INVAL),
},
_ => return Err(ERRNO_INVAL),
};
stream.input.set(None);

Loading…
Cancel
Save