numfmt panics (str char-boundary) on a number using a multibyte locale decimal separator before a multibyte char and a suffix
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 24.1k
- Forks
- 2k
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 365
Description
Under a locale whose decimal separator is multibyte (e.g. LC_ALL=ar_SA.UTF-8, where the separator is the Arabic ٫ U+066B, 2 bytes), numfmt aborts on an input like 1٫€K.
Steps to reproduce
$ LC_ALL=ar_SA.UTF-8 numfmt --from=si '1٫€K'
thread 'main' panicked at src/uu/numfmt/src/format.rs:70:20:
byte index 4 is not a char boundary; it is inside '€' (bytes 3..6) of `1٫€K`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Aborted (core dumped)
$ echo $?
134
The three match arms of find_valid_number_with_suffix each abort on a matching shape (all under LC_ALL=ar_SA.UTF-8):
| input | site | arm |
|---|---|---|
numfmt --from=si '1٫€K' |
format.rs:70 |
(Some(suffix), None) |
numfmt --from=si '1٫€Kx' |
format.rs:76 |
(Some(suffix), Some(_)) |
numfmt --from=auto '1٫€Ki' |
format.rs:73 |
(Some(suffix), Some('i')) |
GNU behavior
GNU rejects the malformed input and exit non-zero without crashing.
$ LC_ALL=ar_SA.UTF-8 /usr/bin/numfmt --from=si '1٫€K'
numfmt: invalid suffix in input: '1٫€K'
$ echo $?
2
Root cause
find_valid_number_with_suffix computes numeric_part.len() (a byte length) and then uses it both as a chars().skip(...) char count and as a byte-slice index &s[..=numeric_part.len()]. When the numeric part contains the multibyte separator, those two accountings desync: the char-skip lands on a later valid suffix, but the byte-slice cuts into the multibyte € mid-character, so the str slice panics (byte index N is not a char boundary) — panic=abort → SIGABRT, exit 134.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/uu/numfmt/src/format.rs at find_valid_number_with_suffix and reproduce the three multibyte-locale inputs from the issue. Trace the byte and character-boundary handling, then verify that malformed suffixes are rejected without a panic and that the relevant numfmt tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 84/100