Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fd_seek with whence::set and a negative offset should error #4556

Closed
yagehu opened this issue Apr 12, 2024 · 0 comments · Fixed by #4557
Closed

fd_seek with whence::set and a negative offset should error #4556

yagehu opened this issue Apr 12, 2024 · 0 comments · Fixed by #4557

Comments

@yagehu
Copy link
Contributor

yagehu commented Apr 12, 2024

Describe the bug

fd_seek with whence set to set and a negative should error. It is the case on Linux host and other Wasm runtimes. However, Wasmer happily cast the negative offset to an unsigned offset and performs the seek.

$ wasmer -vV; rustc -vV
wasmer 4.2.8 (fe3c6d0 2024-04-11)
binary: wasmer-cli
commit-hash: fe3c6d0461f2ee646fd38d1d6480d7c3a30fec74
commit-date: 2024-04-11
host: x86_64-unknown-linux-gnu
compiler: singlepass,cranelift
rustc 1.77.1 (7cf61ebde 2024-03-27)
binary: rustc
commit-hash: 7cf61ebde7b22796c69757901dd346d0fe70bd97
commit-date: 2024-03-27
host: x86_64-unknown-linux-gnu
release: 1.77.1
LLVM version: 17.0.6

Steps to reproduce

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

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

Compile this snippet to wasm32-wasi and run it with wasmer.

Expected behavior

The above snippet should print fd_seek errno INVAL (error 28).

Actual behavior

fd_seek ok new offset 18446744073709551615

Additional context

I have a fix. Will submit a PR.

yagehu added a commit to yagehu/wasmer that referenced this issue Apr 12, 2024
This commit fixes [wasmerio#4556][1].  Passing in a negative offset along with
`whence::set` causes wasmer to erroneously seek to a very large offset.

[1]: wasmerio#4556
yagehu added a commit to yagehu/wasmer that referenced this issue Apr 12, 2024
This commit fixes [wasmerio#4556][1].  Passing in a negative offset along with
`whence::set` causes wasmer to erroneously seek to a very large offset.

[1]: wasmerio#4556
theduke pushed a commit that referenced this issue Apr 12, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant