diff panics on an oversized inline context count (`-c`/`-u`/`-C`/`-U`): parse overflow and capacity overflow
まだ誰も着手していません。
評価
調査の方向性
src/params.rs の279行目と323行目付近にある parse_params の箇所から始め、次に issue にある過大な -c コマンドと -u コマンドを再現してください。既存のパラメータ解析と、近くにあるテストまたはテストの規約を確認してください。過大なコンテキスト数で panic が発生しなくなり、報告されている GNU diff の動作どおり、diff が通常の出力と終了ステータス1で完了すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Summary
diff with an inline numeric context count whose digits exceed usize::MAX — e.g. -u99999999999999999999, -c99999999999999999999, --context=…, --unified=…, -C…, -U… — panics and aborts (exit 134). The option parser captures the digit run with a regex, then does numvalue.as_str().parse::<usize>().unwrap(); an out-of-range value makes parse return Err(PosOverflow) and the bare .unwrap() aborts. GNU diff accepts the oversized count (clamps it) and produces the diff normally, exit 1.
Steps to reproduce
$ printf 'a\n' > f1; printf 'b\n' > f2
$ diffutils diff -u99999999999999999999 f1 f2
thread 'main' panicked at src/params.rs:323:73:
called `Result::unwrap()` on an `Err` value: ParseIntError { kind: PosOverflow }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Aborted (core dumped)
$ echo $?
134
The context (-c/-C/--context) forms hit the sibling site src/params.rs:279:
$ diffutils diff -c99999999999999999999 f1 f2
thread 'main' panicked at src/params.rs:279:73:
called `Result::unwrap()` on an `Err` value: ParseIntError { kind: PosOverflow }
$ echo $?
134
Root cause
parse_params in src/params.rs captures the count with a regex \d+/\d*
that does not bound the digit-run length, then unwraps the parse:
// src/params.rs:279 (context) and :323 (unified)
let context = numvalue.as_str().parse::<usize>().unwrap();
A digit string larger than usize::MAX (e.g. 99999999999999999999) parses to Err(ParseIntError { kind: PosOverflow }), and the unconditional .unwrap() aborts.
Found by our static analysis tooling.
- 主要言語
- Rust
- スター
- 276
- フォーク
- 39
- 平均マージ
- 3時間 27分
- マージ済み PR(30日)
- 3
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
uutils/diffutils のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 64/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 76/100
uutils/diffutils の issue をすべて見る
似ている issue
-
risk:low runtime status:in-progress type:test
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
EricSpencer00/Resilient#4835 · コメント 1 件 ·
-
agent:ready documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
cesarferreira/stax#890 ·
-
bug
難易度 1/5 1時間未満 初心者へのやさしさ 90/100