Skip to content

numfmt: fix panic on multibyte locale decimal separator - #14167

Open
MadeNavaneeth wants to merge 1 commit into
uutils:mainfrom
MadeNavaneeth:fix/numfmt-multibyte-panic
Open

numfmt: fix panic on multibyte locale decimal separator#14167
MadeNavaneeth wants to merge 1 commit into
uutils:mainfrom
MadeNavaneeth:fix/numfmt-multibyte-panic

Conversation

@MadeNavaneeth

Copy link
Copy Markdown
Contributor

Fixes #13937

What

numfmt panics with byte index N is not a char boundary when the input contains a multibyte locale decimal separator (e.g. Arabic ٫ U+066B in ar_SA.UTF-8) before a multibyte character and a suffix.

Root cause

find_valid_number_with_suffix used numeric_part.len() (byte length) as a char count in chars().skip(). When the numeric part contains multibyte characters, the byte count exceeds the char count, causing the char iterator to overshoot and the byte-slice index to land mid-character.

Fix

  • Use numeric_part.chars().count() for the chars().skip() call
  • Compute byte indices via char_indices().nth() for string slicing

Testing

  • All 52 existing numfmt unit tests pass
  • cargo clippy -p uu_numfmt -- -D warnings clean
  • Manual test: LC_ALL=ar_SA.UTF-8 numfmt --from=si '1٫€K' now exits with error 2 instead of panicking

🤖 Generated with Codebuff
Co-Authored-By: Codebuff noreply@codebuff.com

@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/cut/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/pid-pipe (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/symlink (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)

`find_valid_number_with_suffix` used `numeric_part.len()` (byte count)
as a char count in `chars().skip()`, causing desync when the numeric
part contains multibyte characters (e.g. Arabic `٫` separator). This
led to slicing into a multibyte char boundary and panicking.

Fixed by using `chars().count()` for char iteration and computing
byte indices via `char_indices().nth()` for string slicing.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@MadeNavaneeth
MadeNavaneeth force-pushed the fix/numfmt-multibyte-panic branch from 59a618a to 057d56a Compare August 27, 2026 04:15
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 (str char-boundary) on a number using a multibyte locale decimal separator before a multibyte char and a suffix

1 participant