wasi-preview1-component-adapter: fd_readdir duplicates a truncated entry after synthetic dot entries
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 69/100
調査の方向性
Start in crates/wasi-preview1-component-adapter/src/lib.rs at fd_readdir and DirectoryEntryIterator::next, then trace how the cached truncated entry is handled when resuming a directory stream. Use the standalone C reproducer and its split/resume comparison to confirm the duplicate entry. Done means resumed output matches a single full read without duplicated entries or shifted cookies; the issue reports 30 regression cases for broader verification.
索引モデルが issue の本文から書いたものです。
説明
wasi-preview1-component-adapter: fd_readdir duplicates a truncated entry after synthetic dot entries
Summary
When a 23-byte buffer truncates the first dirent and cookie 0 is used for the next large read, Direct P1 returns ., .., then the directory files. The adapter returns ., .., . again, then the files. This violates split/resume equivalence with one full read.
Confirmed with the standalone C program below, without any custom test driver or trace format. Each lane reproduced the same output 5/5 times in fresh directories on Wasmtime 46.0.0 (Release and Debug), 47.0.2, and 50.0.1. Wasmtime 50.0.1 was the latest upstream release at verification time.
Minimal reproducer (repro.c)
#define _POSIX_C_SOURCE 200809L
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <wasi/api.h>
int main(void) {
unsigned char small[23], large[4096];
__wasi_size_t used1 = 0, used2 = 0;
mkdir("testdir", 0755);
for (char name = 'a'; name <= 'd'; name++) {
char path[32];
snprintf(path, sizeof(path), "testdir/%c.txt", name);
close(open(path, O_CREAT | O_WRONLY, 0644));
}
int fd = open("testdir", O_RDONLY | O_DIRECTORY);
__wasi_errno_t error1 = __wasi_fd_readdir(fd, small, 23, 0, &used1);
__wasi_errno_t error2 = __wasi_fd_readdir(fd, large, 4096, 0, &used2);
printf("first: errno=%u used=%u\n", error1, (unsigned)used1);
printf("second: errno=%u used=%u entries:", error2, (unsigned)used2);
for (size_t offset = 0; offset + sizeof(__wasi_dirent_t) <= used2;) {
__wasi_dirent_t entry;
memcpy(&entry, large + offset, sizeof(entry));
if (offset + sizeof(entry) + entry.d_namlen > used2) break;
printf(" %.*s(next=%llu)", (int)entry.d_namlen, large + offset + sizeof(entry),
(unsigned long long)entry.d_next);
offset += sizeof(entry) + entry.d_namlen;
}
printf("\n");
close(fd);
return 0;
}
Exact commands
Run in a new empty directory. The first command downloads the official v50.0.1 command adapter; clang, wasm-tools, and wasmtime must be on the stated paths or adjusted to local installations.
curl -fLO https://github.com/bytecodealliance/wasmtime/releases/download/v50.0.1/wasi_snapshot_preview1.command.wasm
/opt/wasi-sdk/bin/clang --target=wasm32-wasip1 -std=c17 -O2 -Wall -Wextra -Werror repro_rc_dir_split_resume.c -o repro_p1.wasm
wasm-tools component new repro_p1.wasm --adapt wasi_snapshot_preview1=wasi_snapshot_preview1.command.wasm -o repro_adapter.wasm
wasmtime run --dir . repro_p1.wasm; wasmtime run --dir . repro_adapter.wasm
Expected vs. actual output (Wasmtime 50.0.1)
Direct P1 (expected):
first: errno=0 used=23
second: errno=0 used=167 entries: .(next=1) ..(next=2) c.txt(next=3) b.txt(next=4) d.txt(next=5) a.txt(next=6)
Adapter P2 (actual):
first: errno=0 used=23
second: errno=0 used=192 entries: .(next=1) ..(next=2) .(next=1) c.txt(next=4) b.txt(next=5) d.txt(next=6) a.txt(next=7)
Root cause
On truncation, fd_readdir saves the stream, cookie - 1, and cached_dirent (lib.rs:1502-1506). On resume, it sets use_cache: true (lib.rs:1413-1419). However, DirectoryEntryIterator::next handles synthetic ./.. from current_cookie before checking use_cache (lib.rs:1536-1571). The cached truncated entry is consequently emitted after the synthetic entries, duplicating it and shifting later cookies. The ordering remains in v50.0.1.
Suggested fix and causal evidence
When resuming a cached stream, yield cached_dirent before the synthetic dot-entry branches. The existing v46 cookie_resume_fix.patch used that ordering. Across 30 regression cases, violations went from 8 unpatched to 0 patched and back to 8 reverted; the reverted adapter binary matched the original.
- 主要言語
- 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時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
area: plugins bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
clipy-recorder/clipy#1039 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
valkey-io/valkey-glide#7975 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
gofractally/psibase#2379 ·
メンテナーはふだん 3 日以内に返信
-
Qwen stream parser: a chunk with "error": null is treated as a stream error対応中かも @Beehtrix が今日担当しました。 オープンarea:models bug good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
brekkylab/ailoy#681 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信