nushell / reedline

A feature-rich line editor - powering Nushell
https://docs.rs/reedline/
MIT License
514 stars 141 forks source link

Index out of bounds #769

Open RGBCube opened 6 months ago

RGBCube commented 6 months ago

Platform: Linux, NixOS Terminal software: Ghostty

I get this when I do ffmpeg -i RGBCube.gif -crf, assuming ffmpeg is installed.

thread 'main' panicked at /build/rustc-1.75.0-src/library/core/src/str/mod.rs:666:13:
byte index 4 is out of bounds of `dds`
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::str::slice_error_fail_rt
   3: core::str::slice_error_fail
   4: reedline::menu::columnar_menu::ColumnarMenu::create_string
   5: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
   6: <alloc::string::String as core::iter::traits::collect::FromIterator<alloc::string::String>>::from_iter
   7: <reedline::menu::columnar_menu::ColumnarMenu as reedline::menu::Menu>::menu_string
   8: reedline::painting::painter::Painter::print_menu
   9: reedline::painting::painter::Painter::repaint_buffer
  10: reedline::engine::Reedline::repaint
  11: reedline::engine::Reedline::read_line
  12: nu_cli::repl::evaluate_repl
  13: nu::run::run_repl
  14: nu::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Here is a recording, but it doesn't show the trace as it appears for a split second: https://asciinema.org/a/oO8bzFkNpKFd3aFVq7Bfatr2d

The .cast file has it, though.

Here is my completer config:

$env.config.completions = {
  algorithm:      prefix
  case_sensitive: false
  partial:        true
  quick:          true
  external: {
    enable:      true
    max_results: 100
    completer:   {|tokens: list<string>|
      let expanded = scope aliases | where name == $tokens.0 | get --ignore-errors expansion.0

      mut expanded_tokens = if $expanded != null and $tokens.0 != "cd" {
        $expanded | split row " " | append ($tokens | skip 1)
      } else {
        $tokens
      }

      $expanded_tokens.0 = ($expanded_tokens.0 | str trim --left --char "^")

      fish --command $"complete '--do-complete=($expanded_tokens | str join ' ')'"
      | $"value(char tab)description(char newline)" + $in
      | from tsv --flexible --no-infer
    }
  }
}

Everything is from nixpkgs unstable.

RGBCube commented 6 months ago

The output of fish --command "complete '--do-complete=ffmpeg -i RGBCube.gif -crf'" is this:

comfortnoise    RFC 3389 comfort noise generator
dds     DirectDraw Surface image decoder
derf_dpcm       DPCM Xilam DERF
sunrast Sun Rasterfile image

And then you do the pipeline and get this:

╭───┬──────────────┬──────────────────────────────────╮
│ # │    value     │           description            │
├───┼──────────────┼──────────────────────────────────┤
│ 0 │ comfortnoise │ RFC 3389 comfort noise generator │
│ 1 │ dds          │ DirectDraw Surface image decoder │
│ 2 │ derf_dpcm    │ DPCM Xilam DERF                  │
│ 3 │ sunrast      │ Sun Rasterfile image             │
╰───┴──────────────┴──────────────────────────────────╯

Seems normal to me, the issue isn't in the completer?

fdncred commented 6 months ago

What version of nushell are you running?

I've seen this ColumnarMenu involved in panics a few times recently. @Tastaturtaste and @maxomatic458 have worked on menus most recently, maybe they have an idea?

maxomatic458 commented 6 months ago

i think it might be this line here: https://github.com/nushell/reedline/blob/0698712701418a7212ebf75d5724d72eccc4b43f/src/menu/columnar_menu.rs#L305

we could probably add a check there and if it fails we just dont style (looks like that can fail with some external completers)

ill try to make a PR for this later today

RGBCube commented 6 months ago

What version of nushell are you running?

I've seen this ColumnarMenu involved in panics a few times recently. @Tastaturtaste and @maxomatic458 have worked on menus most recently, maybe they have an idea?

0.90.1

fdncred commented 6 months ago

@RGBCube can you try 0.91.1 and see if it's still there?

RGBCube commented 6 months ago

@RGBCube can you try 0.91.1 and see if it's still there?

Yes, the problem persists.

fdncred commented 5 months ago

@maxomatic458 do you have time to look into fixing this or did I miss it already?

maxomatic458 commented 5 months ago

@fdncred https://github.com/nushell/reedline/pull/782 should fix this