uniq: overflowing -f/-s/-w values with trailing garbage are silently accepted

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

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

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

2026年11月3日 から。

  • #16158 @huuan26 による — オープン

評価

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

調査の方向性

バグは 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 の本文から書いたものです。

説明

U - uniq

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

環境構築

Codespaces で開く

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

はじめの一歩

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

uutils/coreutils のほかの issue

uutils/coreutils の issue をすべて見る

似ている issue

Rust の issue をもっと見る

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

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