fold: tab after an 8 KiB buffer flush exceeds the requested width

Aperta Adatta ai principianti
#16,067 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
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
cli

Direzione di ricerca

Inizia da src/uu/fold/src/fold.rs, leggendo maybe_flush_unbroken_output e il ramo della tabulazione in process_ascii_line. Riproduci il problema con il comando nel report, quindi aggiungi un test di regressione per 8192 caratteri a seguiti da una tabulazione e X. Il lavoro è completato quando fold -w8192 mette la tabulazione sulla riga successiva, in linea con l’output previsto.

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

Descrizione

U - fold

fold can exceed the requested column width when a tab immediately follows an output-buffer flush. With 8192 a characters followed by a tab and X, fold -w8192 keeps the tab on the first line, making that line 8200 columns wide. GNU puts the tab on the next line.

Reproduced on Linux x86_64 (Debian 13), LC_ALL=C, with uutils 0.13.0 built from main at 824cdb27175eb644973254dee1eb58fc25088c83. Compared with GNU coreutils 9.12 using the reference package linked in CONTRIBUTING.md; GNU 9.7 gives the same expected result.

From the repository root:

cargo build --no-default-features --features fold
export LC_ALL=C LANG=C
python3 -c 'import sys; sys.stdout.buffer.write(b"a" * 8192 + b"\tX\n")' > fold-input
target/debug/coreutils fold -w8192 fold-input | tail -c 6 | od -An -t x1

Actual last six bytes:

61 61 09 0a 58 0a

Expected last six bytes (GNU):

61 61 0a 09 58 0a

In full, expected output is 8192 a characters followed by \n\tX\n; actual output is 8192 a characters followed by \t\nX\n. Both implementations exit 0 with no stderr. The same failure occurs with piped input and with 16384 a characters at -w16384. Adding -s avoids it for these inputs.

The cause appears to be the interaction between maybe_flush_unbroken_output, which clears the output buffer without resetting the column count, and the tab branch in process_ascii_line, which only folds if !ctx.output.is_empty(). After a flush, an empty buffer does not mean the current output line is empty, so the required fold is skipped.

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

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.