uutils / uutils/diffutils

diff panics on an oversized inline context count (`-c`/`-u`/`-C`/`-U`): parse overflow and capacity overflow

Offen Anfängerfreundlich
#245 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Rust
Sterne
276
Forks
39
Ø Merge
3 Std. 27 Min.
Gemergte PRs (30 T.)
3

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in src/params.rs bei den parse_params-Stellen um die Zeilen 279 und 323 und reproduziere dann die übergroßen -c- und -u-Befehle aus dem Issue. Prüfe die vorhandene Parameteranalyse und die nahegelegenen Tests bzw. Testkonventionen. Erledigt ist es, wenn übergroße Kontextanzahlen keinen panic mehr auslösen und diff mit normaler Ausgabe und Exit-Status 1 abgeschlossen wird, entsprechend dem gemeldeten GNU diff-Verhalten.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
rust
Bereich
cli
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Ruhig
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
72/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.