Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

shuf: exhausted random source destroys the input during an in-place shuffle

オープン 初心者向け
#15,915 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@limadog9 がすでに取り組んでいます。

2026年10月27日 から。

  • #15916 @limadog9 による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
rust
領域
cli, testing

調査の方向性

src/uu/shuf/src/shuf.rsを読み、特にopen_output()とshuf_exec()のシャッフル処理を確認してください。次に、既存のshuf統合テストを調べ、インプレース出力で乱数ソースが枯渇する場合の回帰テストを追加してください。コマンドが入力を保持したまま乱数ソースのエラーを報告し、回帰テストが成功すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

U - shuf

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

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

uutils/coreutils のほかの issue

uutils/coreutils の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。