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時間
- マージ済み PR(30日)
- 357
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 日以内に返信
uutils/coreutils の issue をすべて見る
似ている 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 件 ·
メンテナーはふだん 1 日以内に返信
-
area/desktop-shell
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
yantrikos/yantrik-os#1012 ·
メンテナーはふだん 1 日以内に返信