wasip1-adapter: invalid UTF-8 path bytes trap instead of returning an error
维护者通常 1 天内回复
@NaniToka 已经在做这个了。
开始于 2026年11月23日。
评估
调研方向
Start in crates/wasi-preview1-component-adapter/src/lib.rs, around lines 1781-1787 and 1912-1927, where path byte slices are passed to P2 string parameters. Build the reproducer with the Wasm C toolchain and run it under wasmtime run -S preview2=y, checking the path_* operations for index 0 through 6. Done means each invalid-UTF-8 path returns __WASI_ERRNO_ILSEQ (errno 25) instead of trapping, matching the Direct WASIp1 output.
由索引模型根据 Issue 内容生成。
描述
Environment
- Wasmtime v50.0.1 (
c307ec81de02852d815e9849f7c89d955c03c30d), x86_64 Linux wasi_snapshot_preview1.command.wasmshipped with v50.0.1- Current
main(fb792bf7a143801c22c0ba5b16fe2c6085a8598b) still passes unchecked byte slices to P2 string parameters, for example atcrates/wasi-preview1-component-adapter/src/lib.rs:1781-1787and1912-1927.
Summary and root cause
Passing a path containing an invalid UTF-8 byte to path_open and the other path operations traps the guest through the adapter. Direct WASIp1 instead returns an error and lets the application continue.
The adapter constructs a &[u8] and passes it directly to a P2 interface whose Canonical ABI type is string. The runtime rejects the invalid string while lifting the import argument. No explicit UTF-8 validation in the adapter converts this condition into a WASI errno.
Minimal reproducer
The argument selects path_open, path_create_directory, path_unlink_file, path_remove_directory, path_rename, path_filestat_get, or path_symlink (0 through 6).
#include <wasi/api.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
const char bad[] = {'x', (char)0xff, 0};
__wasi_fd_t fd = -1;
__wasi_filestat_t stat = {0};
__wasi_rights_t rights = __WASI_RIGHTS_FD_READ | __WASI_RIGHTS_FD_WRITE
| __WASI_RIGHTS_PATH_OPEN;
__wasi_errno_t e;
int which = argc > 1 ? atoi(argv[1]) : 0;
switch (which) {
case 0: e = __wasi_path_open(3, 0, bad, 0, rights, rights, 0, &fd); break;
case 1: e = __wasi_path_create_directory(3, bad); break;
case 2: e = __wasi_path_unlink_file(3, bad); break;
case 3: e = __wasi_path_remove_directory(3, bad); break;
case 4: e = __wasi_path_rename(3, bad, 3, "new"); break;
case 5: e = __wasi_path_filestat_get(3, 0, bad, &stat); break;
default: e = __wasi_path_symlink(bad, 3, "new"); break;
}
printf("operation=%d errno=%u\n", which, e);
return 0;
}
"$WASI_SDK_PATH/bin/clang" --target=wasm32-wasip1 -O1 invalid_utf8.c -o invalid_utf8.p1.wasm
wasm-tools component new invalid_utf8.p1.wasm \
--adapt wasi_snapshot_preview1=wasi_snapshot_preview1.command.wasm \
-o invalid_utf8.adapter.wasm
mkdir -p fs
wasmtime run -S preview2=y -S inherit-env=n --dir fs::. invalid_utf8.p1.wasm 0
wasmtime run -S preview2=y -S inherit-env=n --dir fs::. invalid_utf8.adapter.wasm 0
Actual output
Direct WASIp1 exits successfully and prints:
operation=0 errno=25
Adapter P2 exits with a guest Wasm trap. The terminal cause is:
invalid utf-8 sequence of 1 bytes from index 1
The seven operations in this reproducer plus path_link, path_readlink, and path_filestat_set_times were each tested three times. Direct WASIp1 returned EILSEQ (errno=25, __WASI_ERRNO_ILSEQ) in every run; each adapter run trapped with the same UTF-8 conversion error.
Expected output
The adapter should reject the invalid path with EILSEQ (__WASI_ERRNO_ILSEQ) rather than trapping the guest, matching both Direct WASIp1 and the wasi-libc P2 backend. This is a correctness and robustness report, not a security report.
Suggested fix
Validate path bytes with str::from_utf8 before crossing the P2 string boundary and return an appropriate WASI error on failure. Apply the same handling consistently to path parameters and symlink targets.
- 主要语言
- Rust
- 星标
- 18.9k
- 派生
- 2k
- 平均合并
- 1 天 6 小时
- 30 天内合并 PR
- 238
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bytecodealliance/wasmtime 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
bytecodealliance/wasmtime#15536 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
bytecodealliance/wasmtime#15455 · 1 条评论 ·
维护者通常 1 天内回复
-
wasi-preview1-component-adapter: fd_write does not invalidate cached InputStream, causing stale reads可能已有人在做 @dpfens 于 13 天前认领。 未关闭wasi
难度 2/5 1-3 小时 新手友好度 72/100
bytecodealliance/wasmtime#15296 ·
维护者通常 1 天内回复
-
bug wasm-proposal:exceptions wasmtime:debugging
难度 2/5 1-3 小时 新手友好度 76/100
bytecodealliance/wasmtime#14102 ·
维护者通常 1 天内回复
-
wasm-proposal:gc
难度 2/5 1-3 小时 新手友好度 62/100
bytecodealliance/wasmtime#13808 · 2 条评论 ·
维护者通常 1 天内回复
查看 bytecodealliance/wasmtime 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
area: settings bug Haiku review: no-score ui
难度 2/5 1-3 小时 新手友好度 78/100
MMFoundation/WallpaperMachine#346 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
rubys/roundhouse#2473 ·
-
bug mod: quantum info
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复