uniq: overflowing -f/-s/-w values with trailing garbage are silently accepted
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
バグは src/uu/uniq/src/uniq.rs の opt_parsed(355〜360行目付近)にあり、すべての PosOverflow パースエラーを usize::MAX に変換しています。まず cargo build -p uu_uniq と issue に記載の printf/-f コマンドで再現させ、そのうえでオーバーフローの経路を確認してください。オーバーフローする数値の後に余分な文字が続く場合に GNU と同じ "invalid number of fields to skip" メッセージを出して終了コード 1 で拒否され、18446744073709551616 のような有効だが大きすぎる数値は引き続き受け入れられれば完了です。
索引モデルが issue の本文から書いたものです。
説明
uniq accepts a malformed numeric option when the digit prefix overflows usize before the parser reaches an invalid suffix. With -f or -s, it then skips the entire comparison key and collapses distinct input lines into one, exiting successfully instead of rejecting the argument.
Verified on Linux x86_64 (Debian 13), LC_ALL=C LANG=C, using uutils 0.13.0 built from main at 9cc868bcab387842ea2fa7b8e85c76e05860c51f. Compared with GNU coreutils 9.12 from the reference package linked in CONTRIBUTING.md, and GNU 9.7.
Reproduction
From the repository root:
cargo build --locked -p uu_uniq
export LC_ALL=C LANG=C
printf 'first\nsecond\nthird\n' | target/debug/uniq -f 18446744073709551616x
printf 'status=%s\n' "$?"
Actual stdout:
first
status=0
Stderr is empty. GNU 9.12 and 9.7 produce no filtered output, report "18446744073709551616x: invalid number of fields to skip", and exit 1.
Replacing -f with -s also incorrectly prints only first and exits 0. With -w, uutils accepts the malformed count and prints all three lines with status 0; GNU rejects it.
Control cases on x86_64:
- 18446744073709551616 without the x is accepted by both implementations. A valid oversized count should remain accepted.
- 18446744073709551615x is rejected by both. Adding one to the numeric prefix causes uutils to stop rejecting the invalid suffix.
Cause
opt_parsed in uniq.rs:355-360 converts every PosOverflow parse error into usize::MAX. Integer parsing can report overflow before examining the rest of the string, so this does not establish that the complete argument is numeric. Validate the entire argument before accepting an overflowing value.
No matching report was found in searches of open and closed issues and relevant PRs. Related #15970 concerns error wording for values that are already rejected. Its PR #15971 retains the unconditional PosOverflow acceptance, so this is a separate validation problem.
- 主要言語
- Rust
- スター
- 24.3k
- フォーク
- 2.1k
- 平均マージ
- 2日 7時間
- マージ済み PR(30日)
- 397
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
uutils/coreutils のほかの issue
-
pr: -o/--indent does not pad the header line対応中かも @emirmrkaljevic が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
realpath: empty operand aborts with a garbled error instead of being reported as missing対応中かも @emirmrkaljevic が今日担当しました。 オープンU - realpath
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 半日 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信
-
nl: section delimiters reset --join-blank-lines grouping対応中かも @coracoracora が 1 日前に担当しました。 オープンU - nl
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
uutils/coreutils#16130 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
README: Rust version is outdated対応中かも @oech3 が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
uutils/coreutils#16097 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
uutils/coreutils の issue をすべて見る
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
メンテナーはふだん 1 日以内に返信
-
🐞 bug 🧩 bevy_gantz_egui
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
nannou-org/gantz#500 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
metasequoiaime/msime#10989 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
fritzprix/libr-agent#2612 ·
メンテナーはふだん 1 日以内に返信
-
find: -printf %h drops a doubled slash対応中かも @qodelicious が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信