console-rs / indicatif

A command line progress reporting library for Rust
MIT License
4.21k stars 238 forks source link

`attempt to add with overflow` when using MultiProgress with hidden target #602

Closed cvijdea-bd closed 7 months ago

cvijdea-bd commented 8 months ago

Describe the bug It seems that indicatif::multi::MultiState::draw panic with overflow in debug mode, at line 301 line_count is usize::MAX because width is 0.

thread 'fuzz' panicked at %USERPROFILE%\.cargo\git\checkouts\indicatif-f02645b5057a6299\a7456f6\src\multi.rs:305:13:
attempt to add with overflow
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/4578435e1695863d921c7763d5a0add98f8e3869/library\std\src\panicking.rs:597
   1: core::panicking::panic_fmt
             at /rustc/4578435e1695863d921c7763d5a0add98f8e3869/library\core\src\panicking.rs:72
   2: core::panicking::panic
             at /rustc/4578435e1695863d921c7763d5a0add98f8e3869/library\core\src\panicking.rs:127
   3: indicatif::multi::MultiState::draw
             at %USERPROFILE%\.cargo\git\checkouts\indicatif-f02645b5057a6299\a7456f6\src\multi.rs:301
   4: indicatif::multi::MultiState::suspend<[redacted],tuple$<> >
             at %USERPROFILE%\.cargo\git\checkouts\indicatif-f02645b5057a6299\a7456f6\src\multi.rs:392
   5: indicatif::multi::MultiProgress::suspend<[redacted],tuple$<> >
             at %USERPROFILE%\.cargo\git\checkouts\indicatif-f02645b5057a6299\a7456f6\src\multi.rs:187
   [...]

To Reproduce

let multibar = MultiProgress::with_draw_target(ProgressDrawTarget::hidden());
multibar.suspend(|| println!("crash"));

Expected behavior No crash

Additional context Using latest commit a7456f6 from git master.

djc commented 8 months ago

Thanks for reporting, would you be able to submit a PR?

cvijdea-bd commented 8 months ago

I would but I have no clue what the fix should be. My first idea is to just slap an if width == 0 { return Ok(()); } after https://github.com/console-rs/indicatif/blob/a7456f65b679f2f286e6c62f10458a080bc12506/src/multi.rs#L261-L270,

but I don't know the code well enough to tell if that would skip any important cleanup or otherwise relevant stuff