bytecodealliance / bytecodealliance/wasmtime

fd_seek on FIFO returns 0 instead of -1

Open
#12,913 2 comments 0 reactions 1 assignee Claimed by @pchickey View on GitHub
bug
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

### Test Case

When calling `fseek(f, 0, SEEK_END)` on a FIFO from a WASI module,
wasmtime returns 0 (success) instead of an error. This makes it impossible to
detect non-seekable streams from within WASI code.

This seems to be a regression: it fails with wasmtime-py 41.0.0, wasmtime-py 42.0.0,
wasmtime CLI 44.0.0, but seems to work with a wasmtime 11.0 which I happened to have around.

The correct return value should be -1, but broken versions return 0.
Native Linux and wasmer 7.1.0 both correctly return -1.

```c
// test_fifo_seek.c
#include

int main(int argc, char **argv) {
FILE *f = fopen(argv[1], "r");
if (!f) { printf("fopen failed\n"); return 1; }
long cur = ftell(f);
printf("ftell: %ld\n", cur);
int r = fseek(f, 0, SEEK_END);
printf("fseek SEEK_END: %d\n", r);
printf("ftell after SEEK_END: %ld\n", ftell(f));
fclose(f);
return 0;
}
```

### Steps to Reproduce

Compile to WASI (here I'm using zig 0.13.0):
```
zig cc --target=wasm32-wasi-musl -o test_fifo_seek.wasm test_fifo_seek.c
```

Run:
```
mkfifo /tmp/fifo
echo -n "hello" > /tmp/fifo &
wasmtime run --dir /tmp test_fifo_seek.wasm /tmp/fifo
```

### Expected Results

```
ftell: -1
fseek SEEK_END: -1
ftell after SEEK_END: -1
```

### Actual Results

```
ftell: 0
fseek SEEK_END: 0
ftell after SEEK_END: 0
```

### Versions and Environment

41.0.0, 42.0.0, 44.0.0

Operating system: Linux (ubuntu)

Architecture: x86_64

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.