SebTardif opened PR #14135 from SebTardif:fix/dir-read-is-directory to bytecodealliance:main:
Prior discussion: WebAssembly/wasi-libc#869 (@alexcrichton: fix this in Wasmtime instead of extra libc syscalls).
Why
read()on a directory must returnEISDIR(POSIX). Wasmtime'sDescriptor::file()mapped a directory toerror-code::bad-descriptor. wasi-libc then had tostat/get_typejust to remapEBADF. On wasip3,read-via-streamis a tuple import, so that host?trapped instead of returning a guest error.
wasi:filesystemalready documentsis-directoryas theEISDIRanalog.Descriptor::dir()already returnsnot-directoryfor a file. This makesfile()the dual.Change
Descriptor::file()returnsIsDirectoryforDir.- wasip3
read-via-stream: if the descriptor is not a file, return an empty stream and resolve the result future with that error (same shape as p3 TCP receive). Do not trap.- wasip1 guests are unchanged (
fd_readstillEBADF; preview1 adapter stillERRNO_BADF).Tests
p2_file_read_write:read_via_streamon the preopen directory isis-directory.p3_filesystem_file_read_write: the result future isIsDirectory(blocking and non-blocking).Red (unpatched host): p2 guest saw
bad-descriptor(code 3). Green:is-directory(code 14).References
- WebAssembly/wasi-libc#869
- WebAssembly/wasi-libc#865
- rust-lang/rust#160359
- uutils/coreutils#13625
Descriptor::fileas used today was introduced in #11406 (cf88a7c601, 2025-08-12)
SebTardif requested dicej for a review on PR #14135.
SebTardif requested wasmtime-core-reviewers for a review on PR #14135.
SebTardif requested wasmtime-wasi-reviewers for a review on PR #14135.
:thumbs_up: alexcrichton submitted PR review:
Thanks!
alexcrichton has enabled auto merge for PR #14135.
alexcrichton has disabled auto merge for PR #14135.
SebTardif updated PR #14135.
github-actions[bot] added the label wasi on PR #14135.
dicej added PR #14135 Return is-directory when a directory fd is used as a file to the merge queue.
:check: dicej merged PR #14135.
dicej removed PR #14135 Return is-directory when a directory fd is used as a file from the merge queue.
Last updated: Aug 30 2026 at 09:07 UTC