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時間
- マージ済み PR(30日)
- 238
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 日以内に返信
-
Test connection's password prompt says the password is never saved, also for a keychain profileオープン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
Qiskit/qiskit#17699 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信