od: --strings=0 reports stale offsets for empty strings

Aperta Adatta ai principianti
#16,134 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
78/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 extract_strings_from_input in src/uu/od/src/od.rs (intorno alle righe 659-668), dove string_start_offset viene aggiornato solo quando viene letto un byte stampabile, quindi le stringhe vuote riutilizzano l'offset precedente. Riproducilo con il comando printf | od --strings=0 -Ad riportato nell'issue, poi controlla i test esistenti di od sulla gestione delle stringhe. Il lavoro è completato quando una stringa vuota dopo un NUL riporta il proprio offset (byte 4 nell'esempio, e 0 e 1 per due NUL consecutivi), in linea con GNU, e -j4 viene gestito correttamente.

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

Descrizione

U - od

od --strings=0 prints the previous string's starting offset for an empty string. It can even report an offset before the position requested by --skip-bytes.

Reproduced on Linux x86_64 (Debian 13), with uutils 0.13.0 built from main at 43eb6205c20c551480057cdee98e6e7529cd984d. Compared with GNU coreutils 9.12 from the reference package linked in CONTRIBUTING.md and GNU 9.7.

From the repository root:

cargo build --locked -p uu_od
export LC_ALL=C LANG=C
printf 'abc\0\0def\0' | target/debug/od --strings=0 -Ad | cat -A

Actual output ($ marks line endings):

0000000 abc$
0000000 $
0000005 def$

Expected output (GNU 9.12 and 9.7):

0000000 abc$
0000004 $
0000005 def$

The empty string is at byte 4, not byte 0. Both implementations exit 0 with empty stderr.

Adding -j4 produces the same incorrect 0000000 for the first result, even though bytes 0–3 were skipped. Two consecutive NUL bytes also reproduce it: uutils reports offsets 0, 0; GNU reports 0, 1. Nonempty strings and -S1 behave correctly in the control cases.

In extract_strings_from_input, od.rs:659–668, string_start_offset is updated only when a printable byte is read. An empty string contains no such byte, so its output uses the stale offset.

No matching report was found in searches of open and closed issues and related PRs. #11613 concerns unterminated strings with -N, and #15592 concerns hexadecimal padding width; this case uses terminated strings, decimal offsets, and no -N.

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

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.