asciinema / agg

asciinema gif generator
https://docs.asciinema.org/manual/agg/
Apache License 2.0
1.21k stars 44 forks source link

agg panics at runtime at `src/buffer.rs:80:13` of AVT: index out of bounds: the len is 0 but the index is 0 #62

Open hartwork opened 11 months ago

hartwork commented 11 months ago

Describe the bug Hi! Thanks for making asciinema and agg and sharing them as Software Libre! :pray:

I recorded some cast file with asciinema 2.3.0, fed it to agg and it panicked. Note the "width": 0, "height": 0, those were produced by asciinema from…

export COLUMNS=90
export ROWS=20

…in the environment at recording time.

So now for the crashing agg:

# RUST_BACKTRACE=1 ~/.cargo/bin/agg ~/Desktop/bug.cast.txt out.gif |& sed "s,${USER},user123,"
thread 'main' panicked at /home/user123/.cargo/git/checkouts/avt-68339788ba7d673e/28aed2b/src/buffer.rs:80:13:
index out of bounds: the len is 0 but the index is 0
stack backtrace:
   0: rust_begin_unwind
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/std/src/panicking.rs:595:5
   1: core::panicking::panic_fmt
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:67:14
   2: core::panicking::panic_bounds_check
             at /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/panicking.rs:162:5
   3: <avt::terminal::Terminal as avt::parser::Executor>::print
   4: avt::vt::Vt::feed_str
   5: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
   6: std::thread::scoped::scope
   7: agg::run
   8: agg::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
4 / 4 [=====================================================] 100.00 % 221.70/s 

# sed -n '79,81p' ~/.cargo/git/checkouts/avt-*/*/src/buffer.rs
    pub fn print(&mut self, (col, row): VisualPosition, cell: Cell) {
        self[row].print(col, cell);
    }

To Reproduce

  1. Download the attached cast produced by asciinema 2.3.0
  2. Run ~/.cargo/bin/agg bug.cast.txt out.gif
  3. See agg panic

Expected behavior No panic

Versions:

Additional context Please see description

ku1ik commented 1 week ago

So the main problem is the recorder put 0x0 size in the cast file, which we should prevent from happening in the first place. But I think it's a good idea to add a check here in agg and bail if any of the dimensions is lower non-positive.