coreutils icon indicating copy to clipboard operation
coreutils copied to clipboard

fmt: tabs not expanded to spaces when reflowing paragraphs, inter-word spacing wrong

Open Khushi6767 opened this issue 2 weeks ago • 0 comments

Description

When fmt joins lines into a paragraph, GNU fmt expands tab characters to the appropriate number of spaces based on tab-stop positions (multiples of 8). uutils fmt preserves raw tab characters and does not account for their column contribution when computing inter-word spacing. This causes incorrect output across multiple modes: default, -c (crown margin), -s (split-only), and -t (tagged paragraph).

Found via differential fuzzing against GNU coreutils 9.4.

Environment

  • uutils version: 0.13.0 (built from current main)
  • GNU coreutils: 9.4
  • OS: Linux (x86_64)

Reproduction

Test 1: -c (crown margin) — tab expanded to spaces by GNU, kept raw by uutils

$ printf 'hello\nworld\tbye\n' | gnu-fmt -c | cat -A
hello world   bye$

$ printf 'hello\nworld\tbye\n' | uutils-fmt -c | cat -A
hello world^Ibye$

GNU expands the tab between world and bye to 3 spaces (to reach column 16, the next tab stop after column 13). uutils keeps the raw \t.

Test 2: Default mode — inter-word padding after tab is wrong

$ printf 'a\tb\na\tc\n' | gnu-fmt | cat -A
a^Ib a^I  c$

$ printf 'a\tb\na\tc\n' | uutils-fmt | cat -A
a^Ib a^Ic$

GNU pads with 2 extra spaces after the second tab so c starts at column 11 (matching the tab-stop–aware width). uutils outputs no padding.

Test 3: -s (split-only) — trailing space before tab not stripped

$ printf 'x \tb\n' | gnu-fmt -s | cat -A
x^Ib$

$ printf 'x \tb\n' | uutils-fmt -s | cat -A
x ^Ib$

GNU strips the trailing space before the tab. uutils preserves it.

Expected behavior

uutils fmt should match GNU fmt in handling tab characters during paragraph reflowing: expanding tabs to the correct column width and stripping redundant whitespace before tabs.

Additional context

These differences were found by a differential fuzzer that generates random text inputs and compares GNU vs uutils output. The tab handling issue is consistent across all tested seeds and affects the default, -c, -s, and -t modes of fmt.

AI was used to assist with the differential fuzzing harness that discovered this bug.

Khushi6767 avatar Nov 14 '26 18:11 Khushi6767