Commit 93fa095
numfmt: reject an oversized --from-unit/--to-unit instead of panicking
parse_unit_size computed the unit size as `n * multiplier` with an
unchecked multiplication. A large numeric part with a suffix overflows
usize: when the product wraps to exactly 0 (e.g. `--to-unit=18014398509481984Ki`,
2^54 * 1024 = 2^64), the zero unit later reaches `integer % to_unit` and
aborts with a remainder-by-zero; a merely-huge value overflows the
multiply itself under overflow-checks.
Use `checked_mul` so an out-of-range product falls through to the
existing "invalid unit size" error (exit 1), matching GNU numfmt, whose
`unit_to_umax` rejects a value that overflows uintmax_t.1 parent 314110b commit 93fa095
2 files changed
Lines changed: 13 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
204 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
205 | 209 | | |
206 | 210 | | |
207 | 211 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
878 | 878 | | |
879 | 879 | | |
880 | 880 | | |
881 | | - | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
882 | 888 | | |
883 | 889 | | |
884 | 890 | | |
| |||
0 commit comments