Describe the bug
into duration multiplies the input value by its unit's nanosecond factor using unchecked arithmetic. A value large enough that value * factor exceeds i64::MAX overflows: this panics in debug builds (attempt to multiply with overflow) and silently wraps to an incorrect negative/garbage duration in release builds.
The overflow affects several code paths in into duration:
- a unit string, e.g.
9999999999wk
- an integer with
--unit, e.g. <big> | into duration --unit wk
- an
hh:mm:ss clock string with very large hours
How to reproduce
On a debug build:
> "9999999999wk" | into duration
> 9223372036854775807 | into duration --unit wk
> "2562047788015216:00:00" | into duration
Each panics with attempt to multiply with overflow. On a release build the same inputs return a silently incorrect (wrapped) duration instead of an error.
Expected behavior
into duration should never panic on user input. A value too large to represent as a 64-bit nanosecond duration should produce a clear error rather than panicking or silently wrapping.
Configuration
Reproduces on main (0.114.2). The affected code is crates/nu-command/src/conversions/into/duration.rs (string_to_duration, compound_to_duration, parse_clock_duration, and the Value::Int arm of action).
Describe the bug
into durationmultiplies the input value by its unit's nanosecond factor using unchecked arithmetic. A value large enough thatvalue * factorexceedsi64::MAXoverflows: this panics in debug builds (attempt to multiply with overflow) and silently wraps to an incorrect negative/garbage duration in release builds.The overflow affects several code paths in
into duration:9999999999wk--unit, e.g.<big> | into duration --unit wkhh:mm:ssclock string with very large hoursHow to reproduce
On a debug build:
Each panics with
attempt to multiply with overflow. On a release build the same inputs return a silently incorrect (wrapped) duration instead of an error.Expected behavior
into durationshould never panic on user input. A value too large to represent as a 64-bit nanosecond duration should produce a clear error rather than panicking or silently wrapping.Configuration
Reproduces on
main(0.114.2). The affected code iscrates/nu-command/src/conversions/into/duration.rs(string_to_duration,compound_to_duration,parse_clock_duration, and theValue::Intarm ofaction).