Skip to content

into duration overflows on large values (panic in debug, silent wrap in release) #18592

Description

@santhreal

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions