FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

numfmt: fix panic on multibyte locale decimal separator by MadeNavaneeth · Pull Request #14167 · uutils/coreutils · GitHub

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 commented Aug 26, 2026
edited
Loading

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

github-actions Bot commented Aug 27, 2026
edited
Loading

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/date/date-locale-hour (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/seq/seq-epipe is now passing!

MadeNavaneeth force-pushed the fix/numfmt-multibyte-panic branch 2 times, most recently from 057d56a to ac971d3 Compare August 27, 2026 12:57
`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.
MadeNavaneeth force-pushed the fix/numfmt-multibyte-panic branch from ac971d3 to 5480866 Compare August 27, 2026 15:29
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL