wasi-preview1-component-adapter: fd_readdir duplicates a truncated entry after synthetic dot entries
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 69/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Rust
- Star
- 18.9k
- Fork
- 2k
- Merge trung bình
- 1 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 238
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của bytecodealliance/wasmtime
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
bytecodealliance/wasmtime#15536 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
bytecodealliance/wasmtime#15455 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
wasi-preview1-component-adapter: fd_write does not invalidate cached InputStream, causing stale readsCó thể đã có người làm @dpfens đã nhận 13 ngày trước. Đang mởwasi
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
bytecodealliance/wasmtime#15296 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug wasm-proposal:exceptions wasmtime:debugging
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
bytecodealliance/wasmtime#14102 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
wasm-proposal:gc
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
bytecodealliance/wasmtime#13808 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của bytecodealliance/wasmtime
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area: plugins bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
clipy-recorder/clipy#1039 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
valkey-io/valkey-glide#7975 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
gofractally/psibase#2379 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Qwen stream parser: a chunk with "error": null is treated as a stream errorCó thể đã có người làm @Beehtrix đã nhận hôm nay. Đang mởarea:models bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
brekkylab/ailoy#681 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày