Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a crash in numfmt when parsing inputs under locales with a multibyte decimal separator by avoiding mixing byte offsets and char iteration, and adds a regression test for the reported panic case.
Changes:
- Fix
find_valid_number_with_suffixto derive the suffix iterator from a byte-slice (s[numeric_part.len()..].chars()) instead ofchars().skip(byte_len). - Add a regression test covering
--from=siand--from=autowithLC_ALL=ar_SA.UTF-8and an invalid multibyte suffix sequence (€…).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/uu/numfmt/src/format.rs | Prevents char-boundary panics by aligning suffix scanning with the numeric prefix byte boundary. |
| tests/by-util/test_numfmt.rs | Adds regression coverage for malformed inputs under a multibyte-decimal locale. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| #[test] | ||
| fn test_from_multibyte_decimal_separator_invalid_suffix() { | ||
| new_ucmd!() | ||
| .env("LC_ALL", "ar_SA.UTF-8") | ||
| .args(&["--from=si", "1٫€K"]) | ||
| .fails_with_code(2) |
Merging this PR will not alter performance
Comparing Footnotes
|
|
Binary size comparison: |
|
GNU testsuite comparison: |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (1)
tests/by-util/test_numfmt.rs:463
- The new regression test sets
LC_ALLtofr_FR. UTF-8(note the stray space) while using the Arabic decimal separator٫in the input. Underfr_FR.UTF-8the decimal separator is,, so this test won't exercise the reported multibyte-decimal-separator path and is likely to fail (or even fail to set the locale). Also, since this test relies on locale env vars, it should be ignored underwasi_runnerlike the existing locale tests in this file, and it’s safer to early-return whenar_SA.UTF-8isn’t available on Unix CI.
#[test]
fn test_from_multibyte_decimal_separator_invalid_suffix() {
new_ucmd!()
.env("LC_ALL", "fr_FR. UTF-8")
.args(&["--from=si", "1٫€K"])
|
I broke it, sorry |
96e37c8 to
912b345
Compare
912b345 to
db756fc
Compare
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 1
| #[test] | ||
| fn test_from_multibyte_decimal_separator_invalid_suffix() { | ||
| new_ucmd!() | ||
| .env("LC_ALL", "fr_FR.UTF-8") |
There was a problem hiding this comment.
, is a single byte here, so this case already passes on main, no?
the bug needs a multibyte separator, so please keep a case that really covers it (and gate it on the locale being there)
|
the ar_SA cases still need to be gated on the locale being there (and ignored on wasi), that's very likely why Tests (wasm32-wasip1) fails |
`find_valid_number_with_suffix` located the suffix with `s.chars().skip(numeric_part.len())`, using `numeric_part.len()` (a byte length) as a char-skip count. When the numeric part holds a multibyte char — e.g. the Arabic decimal separator `٫` (U+066B) under `LC_ALL=ar_SA.UTF-8`, so `1٫€K` parses `1٫` as the numeric part — the byte count skips past the following multibyte `€` onto a later valid suffix, taking a slicing arm; then `&s[..=numeric_part.len()]` cuts `€` mid-char and aborts instead of reporting the invalid suffix like GNU. Index the suffix from the byte offset `numeric_part.len()` (already a char boundary) instead of skipping by chars, so the real next char is examined and an invalid multibyte suffix takes the graceful rejection path. Fixes uutils#13937
db756fc to
e3c6d50
Compare
|
Thanks! Dropped the fr_FR case and kept only the multibyte-separator cases. They now use fa_IR.UTF-8 (same ٫ separator, and the locale CI generates), gated on is_locale_available and ignored on WASI. |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
3 open issues
Review effort: Lite
| let accepts_i = [Unit::Auto, Unit::Iec(true)].contains(&unit); | ||
|
|
||
| let mut characters = s.chars().skip(numeric_part.len()); | ||
| let mut characters = s[numeric_part.len()..].chars(); |
| // fa_IR's decimal separator `٫` is multibyte, so a byte length used as a | ||
| // char count made the suffix lookup slice inside the `€` and panic. | ||
| let locale = "fa_IR.UTF-8"; |


Fixes #13937
numfmtaborts with astrchar-boundary panic on an input like1٫€Kunder a locale whose decimal separator is multibyte (e.g.LC_ALL=ar_SA.UTF-8, where the separator is the Arabic٫U+066B), while GNU rejects it gracefully:Cause
find_valid_number_with_suffixlocated the suffix withs.chars().skip(numeric_part.len()), usingnumeric_part.len()— a byte length — as a char skip count. When the numeric part holds a multibyte char (here the locale decimal separator٫, so1٫is the numeric part withlen() == 3bytes but only 2 chars), the byte count over-skips past the following multibyte€onto a later valid suffix (K), taking a slicing arm;&s[..=numeric_part.len()]then slices to a byte offset inside€and panics.Fix
Index the suffix from the byte offset
numeric_part.len()(s[numeric_part.len()..].chars()) rather than skipping by chars.numeric_partis always a prefix ofs, sonumeric_part.len()is a char boundary and the slice is safe; the real next char (€) is now examined, is not a valid suffix, and the input takes the same graceful "invalid suffix" rejection GNU gives. The existing byte-slices are unaffected — a valid suffix is ASCII, so they remain char-aligned.A regression test covers the
--from=siand--from=autovariants underLC_ALL=ar_SA.UTF-8.