You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
printf aborts on a hex float with a large-negative binary exponent (0x1p-9223372036854775808) #14835
Parsing a hexadecimal floating-point argument whose binary exponent is a large-magnitude negativei64 (e.g. 0x1p-9223372036854775808) overflows bigdecimal's internal i64 scale inside BigDecimal::powi. uutils reaches it from num_parser.rs (base.powi(exponent)), directly under a comment asserting "We cannot overflow/underflow BigDecimal here" — which is false. The exponent is bounded to fit i64 (via to_i64()), but a value near i64::MIN still makes powi accumulate a scale outside i64 range. It is an arithmetic-overflow panic: it aborts a debug / -C overflow-checks=on build (exit 101/134) and wraps silently in a stock --release build.
$ printf'%f' 0x1p-9223372036854775808thread 'main' panicked at bigdecimal-0.4.10/src/arithmetic/multiplication.rs:648:19:attempt to add with overflownote: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
$ echo$?101
Root cause
// src/uucore/src/lib/features/parser/num_parser.rs (hex-float branch)// powi "only" supports i64 values. Just overflow/underflow if the value provided// is > 2**64 or < 2**-64.letSome(exponent) = exponent.to_i64()else{returnErr(make_error(exponent.is_positive(), negative));};let base:BigDecimal = 2.into();// Note: We cannot overflow/underflow BigDecimal here, as we will not be able to// reach the maximum/minimum scale (i64 range).let pow2 = base.powi(exponent);// <- overflows for large-negative exponent
The to_i64() guard only rejects exponents that do not fit i64; it does not bound the magnitude, and the comment's assumption that a within-i64 exponent cannot overflow the scale is wrong — powi(i64::MIN) builds a BigDecimal whose scale accumulation exceeds i64.
Activity
uucore: bound hex float exponent to avoid BigDecimal scale overflow
uucore: bound hex float exponent to avoid BigDecimal scale overflow (u…