diff panics (`into_string().unwrap()`) on a non-UTF-8 argument ending in `--width=N`
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 85/100
Direzione di ricerca
Inizia in src/params.rs, intorno alle regex di width e tabsize alle righe 62-63, quindi esamina la gestione degli argomenti intorno alla riga 116. Riproduci l'argomento --width non UTF-8 mostrato nell'issue e verifica che l'argomento venga trattato come un operando di file invece di causare un panic o di essere accettato come opzione; controlla anche il caso xyz--width=5.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Steps to reproduce
$ printf 'a\nb\nc\n' > A; printf 'a\nX\nc\n' > B
$ diffutils diff $'\xff--width=5' A B
thread 'main' panicked at src/params.rs:116:45:
called `Result::unwrap()` on an `Err` value: "\xFF--width=5"
$ echo $?
134
diff aborts (panic, exit 134) when given a non-UTF-8 argument whose lossy form ends in --width=<digits> — e.g. an argument with a leading invalid byte like $'\xff--width=5'.
Expected behavior
Match GNU: the unrecognized argument is a file operand; with three operands diff reports the extra operand and exits 2.
$ /usr/bin/diff $'\xff--width=5' A B
diff: extra operand 'B'
$ echo $?
2
Root cause
The --width regex lacks a start anchor, unlike the sibling --tabsize one:
// src/params.rs:62-63
let tabsize_re = Regex::new(r"^--tabsize=(?<num>\d+)$").unwrap(); // anchored — safe
let width_re = Regex::new(r"--width=(?P<long>\d+)$").unwrap(); // no leading ^
// src/params.rs:115-116
if width_re.is_match(param.to_string_lossy().as_ref()) { // matches lossy form
let param = param.into_string().unwrap(); // line 116: Err on non-UTF-8
to_string_lossy() maps invalid bytes to U+FFFD, so a non-UTF-8 argument whose tail is --width=N still matches; into_string() then fails on the real bytes.
Fix: anchor the regex at the start (^--width=…$, matching tabsize_re), and/or match on the bytes / avoid into_string().unwrap() so a non-UTF-8 argument falls through to the operand path. (The unanchored regex also makes diff xyz--width=5 silently accept a width option instead of treating it as a filename — same root cause, non-panic symptom.)
Found by our static analysis tooling.
- Lingua principale
- Rust
- Stelle
- 276
- Fork
- 39
- Merge medio
- 3h 27m
- PR unite (30g)
- 3
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di uutils/diffutils
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 64/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 76/100
Tutte le issue di uutils/diffutils
Issue simili
-
risk:low runtime status:in-progress type:test
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
EricSpencer00/Resilient#4835 · 1 commento ·
-
agent:ready documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
cesarferreira/stax#890 ·
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100