Skip to content

numfmt: do not panic on a multibyte whitespace field separator#13485

Merged
sylvestre merged 1 commit into
uutils:mainfrom
leeewee:numfmt-fix-field-multibyte-whitespace
Jul 21, 2026
Merged

numfmt: do not panic on a multibyte whitespace field separator#13485
sylvestre merged 1 commit into
uutils:mainfrom
leeewee:numfmt-fix-field-multibyte-whitespace

Conversation

@leeewee

@leeewee leeewee commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #13482.

write_formatted_with_whitespace normalized the delimiter before the 2nd+ selected field by writing a single space and dropping the first byte of the leading whitespace run with &prefix[1..]. That assumed an ASCII separator, but WhitespaceSplitter splits on Unicode char::is_whitespace, so a multibyte separator (e.g. U+3000 IDEOGRAPHIC SPACE) made &prefix[1..] slice inside the character and abort:

$ numfmt --field 2 $'1 2'
thread 'main' panicked at src/uu/numfmt/src/format.rs:848:24:
byte index 1 is not a char boundary; it is inside '\u{3000}' (bytes 0..3) of ` `
$ echo $?
134

This drops the first character (by its UTF-8 length) instead of the first byte, so the slice always lands on a char boundary. Output becomes 1 2, exit 0.

write_formatted_with_whitespace normalized the delimiter before the
second and subsequent selected fields by writing a single space and
dropping the first byte of the leading whitespace run with `&prefix[1..]`.
That assumed an ASCII separator: WhitespaceSplitter splits on Unicode
`char::is_whitespace`, so a multibyte separator (e.g. U+3000 IDEOGRAPHIC
SPACE) made `&prefix[1..]` slice inside the character and abort with a
char-boundary panic.

Drop the first character instead of the first byte, using its UTF-8
length, so the slice always lands on a char boundary.
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)

@sylvestre
sylvestre merged commit 7807c8d into uutils:main Jul 21, 2026
164 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

numfmt panics (char-boundary) on a multibyte Unicode whitespace separator with --field

2 participants