uutils / uutils/coreutils

seq: format_float_shortest panic when printing absurdly large exponents

Open
#7,632 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - seq
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

While playing with inputs at the edge of maximum possible exponents:

RUST_BACKTRACE=1 cargo run -p uu_seq -- -f "%g" 1e9223372036854775806 1e9223372036854775806 inf
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.18s
     Running `target/debug/seq -f '%g' 1e9223372036854775806 1e9223372036854775806 inf`

thread 'main' panicked at src/uucore/src/lib/features/format/num_format.rs:467:20:
attempt to add with overflow
stack backtrace:
   3: uucore::features::format::num_format::format_float_shortest
             at ./src/uucore/src/lib/features/format/num_format.rs:467:20
   4: <uucore::features::format::num_format::Float as uucore::features::format::num_format::Formatter<&uucore::features::format::extendedbigdecimal::ExtendedBigDecimal>>::fmt
             at ./src/uucore/src/lib/features/format/num_format.rs:278:21
   5: uucore::features::format::Format<F,T>::fmt
             at ./src/uucore/src/lib/features/format/mod.rs:383:9
   6: uu_seq::print_seq
             at ./src/uu/seq/src/seq.rs:265:9
   7: uu_seq::uumain::uumain
             at ./src/uu/seq/src/seq.rs:185:18
   8: uu_seq::uumain
             at ./src/uu/seq/src/seq.rs:88:1
   9: seq::main
             at ./src/uucore/src/lib/lib.rs:157:24
  10: core::ops::function::FnOnce::call_once
             at /home/drinkcat/nobackup/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
1e+9223372036854775806
2e+9223372036854775806
3e+9223372036854775806
4e+9223372036854775806
5e+9223372036854775806
6e+9223372036854775806
7e+9223372036854775806
8e+9223372036854775806
9e+9223372036854775806

%e has similar problems:

RUST_BACKTRACE=1 cargo run -p uu_seq -- -f "%e" 1e9223372036854775807 1e9223372036854775807 inf
thread 'main' panicked at src/uucore/src/lib/features/format/num_format.rs:410:20:
attempt to add with overflow
stack backtrace:
...
   3: uucore::features::format::num_format::format_float_scientific

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 src/uucore/src/lib/features/format/num_format.rs, focusing on format_float_shortest and format_float_scientific, then reproduce the panic with the cargo run commands shown for uu_seq. Done means the equivalent absurd-exponent inputs no longer panic when seq formats them with %g or %e.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.