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

Aperta Adatta ai principianti
#16,122 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
75/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
cli

Direzione di ricerca

Il bug si trova in opt_parsed in src/uu/uniq/src/uniq.rs (intorno alle righe 355-360), che associa ogni errore di parsing PosOverflow a usize::MAX. Inizia riproducendo il problema con cargo build -p uu_uniq e il comando printf/-f dell'issue, poi controlla il percorso di overflow. È completato quando un numero che va in overflow seguito da caratteri spuri viene rifiutato con il messaggio GNU "invalid number of fields to skip" e exit code 1, mentre un numero valido ma troppo grande come 18446744073709551616 continua a essere accettato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Rust
Stelle
24.3k
Fork
2.1k
Merge medio
1g 22h
PR unite (30g)
396

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di uutils/coreutils

Tutte le issue di uutils/coreutils

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.