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::cur underflows #4589

Closed
yagehu opened this issue Apr 22, 2024 · 0 comments · Fixed by #4590
Closed

fd_seek with whence::cur underflows #4589

yagehu opened this issue Apr 22, 2024 · 0 comments · Fixed by #4590

Comments

@yagehu
Copy link
Contributor

yagehu commented Apr 22, 2024

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

yagehu added a commit to yagehu/wasmer that referenced this issue Apr 22, 2024
This commit adds a checked subtraction to `fd_seek` so that passing in a
large negative offset does not underflow.

fixes wasmerio#4589
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