nushell / nushell/nushell

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

Open
#18,592 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
40.5k
Forks
2.3k
Avg merge
1d 19h
Merged PRs (30d)
85

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in crates/nu-command/src/conversions/into/duration.rs and inspect string_to_duration, compound_to_duration, parse_clock_duration, and the Value::Int arm of action. Run the listed large-value reproductions in debug and release builds. Done means every affected input returns a clear error for values beyond 64-bit nanosecond duration range, without panicking or silently wrapping.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.