wasmerio/wasmer

`fd_seek` with `whence::cur` underflows

Closed this issue · 0 comments

Describe the bug

Calling fd_seek with whence::cur and a large enough negative offset underflows.

$ wasmer -vV; rustc -vV
wasmer 4.2.8 (f5b182f 2024-04-18)
binary: wasmer-cli
commit-hash: f5b182fce677570abf4af9b982969d29db7777e5
commit-date: 2024-04-18
host: x86_64-unknown-linux-gnu
compiler: singlepass,cranelift
rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

Steps to reproduce

fn main() {
    unsafe {
        let result = wasi::fd_seek(4, -6551085931117533355, wasi::WHENCE_CUR);

        match result {
            Ok(new_offset) => eprintln!("fd_seek ok new offset {new_offset}"),
            Err(errno) => eprintln!("fd_seek errno {errno}"),
        }
    }
}

Expected behavior

fd_advise should error with something like inval (28).

Actual behavior

fd_advise succeeds, returning a positive offset.

Additional context