shuf: exhausted random source destroys the input during an in-place shuffle
维护者通常 1 天内回复
评估
调研方向
阅读 src/uu/shuf/src/shuf.rs,尤其是 open_output() 和 shuf_exec() 中的洗牌流程。然后检查现有的 shuf 集成测试,并为原地输出时随机源耗尽的情况添加一个回归用例。完成标准是:命令报告随机源错误,同时保留输入,并且回归测试通过。
由索引模型根据 Issue 内容生成。
描述
An in-place shuffle with a readable but exhausted --random-source erases the input file before reporting the error. GNU shuf leaves the file unchanged.
Reproduced on Linux x86_64 at main c1f172886c6643f61ffde5a1ce3db0aaf14e182b, in debug and release builds. References: GNU 9.7 and the project-recommended GNU 9.12 package (9.12-0ubuntu1~ppa1).
Reproduce
From a built repository, using only disposable files:
d=$(mktemp -d)
printf 'one\ntwo\nthree\n' > "$d/input"
: > "$d/seed"
LC_ALL=C target/debug/coreutils shuf \
--random-source="$d/seed" -o "$d/input" "$d/input"
echo "status: $?"
wc -c < "$d/input"
Actual: "shuf: end of random source", exit 1, and input is now 0 bytes.
Expected: exit 1 with the original 14 bytes intact, as with GNU 9.7 and 9.12. Recreate the input before running the GNU comparison.
This also occurs with a nonempty but insufficient random source: 100 input records and a one-byte seed. It affects an existing separate output file and output paths that are hard links or symlinks to the input.
Cause and validation
In src/uu/shuf/src/shuf.rs, open_output() at line 164 calls File::create() before shuf_exec() draws random bytes. An EOF during the shuffle therefore happens after the output has been truncated. The syscall trace confirms O_TRUNC before the random-source EOF read.
Across 16 cases per binary (four random-source conditions and four output relationships), both GNU versions passed. Each uutils build lost data in all eight empty/short-source cases. Sufficient and missing-source controls passed. The existing shuf integration suite passes: 75 passed, 1 ignored.
Related: #13113 fixed truncation when input or random-source opening fails. This case successfully opens the random source and fails later while reading it. Searches of open/closed issues, PRs, and comments found no report of this remaining exhaustion case.
Please delay destructive output opening until the non-repeating shuffle has completed successfully, and add a regression test for random-source exhaustion with in-place output.
- 主要语言
- Rust
- 星标
- 24.3k
- 派生
- 2.1k
- 平均合并
- 1 天 21 小时
- 30 天内合并 PR
- 357
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
uutils/coreutils 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
B - high priority U - tr
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
U - df
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
U - mv
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
fmt: stops at an unreadable file operand and says only 'read error' for a directory可能已有人在做 @emirmrkaljevic 于 1 天前认领。 未关闭U - fmt
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
-
难度 2/5 1-3 小时 新手友好度 72/100
mozilla-services/syncstorage-rs#2715 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 70/100
-
documentation
难度 1/5 1 小时以内 新手友好度 82/100
physicsdolphin/nv-uefi-unlocker#53 · 4 个 reaction ·
维护者通常 1 天内回复
-
area/desktop-shell
难度 2/5 1-3 小时 新手友好度 72/100
yantrikos/yantrik-os#1012 ·
维护者通常 1 天内回复