nuta / nsh

A command-line shell like fish, but POSIX compatible.
906 stars 34 forks source link

Multibyte (and/or double width) character problem #34

Closed s3i7h closed 2 years ago

s3i7h commented 2 years ago

I was trying out nsh on my macbook and encountered this. (might be related to #14 ?)

[ERROR  ] /Users/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/nsh-0.4.2/src/main.rs: panicked at 'called `Result::unwrap()` on an `Err` value: RecvError', /Users/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/nsh-0.4.2/src/bash_server.rs:26:33
[ERROR  ] /Users/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/nsh-0.4.2/src/main.rs: panicked at 'index out of bounds: the len is 20 but the index is 53', /Users/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/nsh-0.4.2/src/mainloop.rs:1153:13
[ERROR  ] /Users/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/nsh-0.4.2/src/main.rs:    0:        0x102083c18 - backtrace::capture::Backtrace::new::hba9adf1e5b3c7a91
   1:        0x10204a7d8 - nsh::main::{{closure}}::h67739294c6afee12
   2:        0x1020ffe9d - std::panicking::rust_panic_with_hook::hae2b05f08a320721
   3:        0x10211dc5c - std::panicking::begin_panic_handler::{{closure}}::h72d68d3a77e0b718
   4:        0x10211dc27 - std::sys_common::backtrace::__rust_end_short_backtrace::h7c5e286792f94edb
   5:        0x10211dbe0 - _rust_begin_unwind
   6:        0x102136d9f - core::panicking::panic_fmt::h1b194bb80d76fb10
   7:        0x102136d66 - core::panicking::panic_bounds_check::hde7f7e34704d5da2
   8:        0x102016118 - nsh::mainloop::Mainloop::handle_key_event::h72f2fc3ed6d69a71
   9:        0x1020119ae - nsh::mainloop::Mainloop::handle_event::h98f98893dfe246aa
  10:        0x10200e02f - nsh::mainloop::Mainloop::run::hd7a071cbdcd9cbdc
  11:        0x1020466e2 - nsh::shell_main::ha315b12f85f157a9
  12:        0x102049ff9 - nsh::main::h367ea8887b771698
  13:        0x101fa32aa - std::sys_common::backtrace::__rust_begin_short_backtrace::hde4e21082195018a
  14:        0x102060794 - _main

[ERROR  ] /Users/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/nsh-0.4.2/src/main.rs: panicked at 'called `Result::unwrap()` on an `Err` value: RecvError', /Users/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/nsh-0.4.2/src/bash_server.rs:26:33

I'm in a LANG=ja_JP.UTF-8 environment, and nsh was acting weird in a directory with a name consisting multibyte letters. (The left prompt and the actual input area were separated way apart) The actual crash occurred when trying to type a letter after completing a multibyte directory name.

PoC:

nsh
$ mkdir ぴーおーしー
$ cd <TAB> <select ぴーおーしー> <return> <type any letter>

(sidenote: ぴーおーしー is "PoC" in Japanese hiragana representation and doesn't mean anything)

s3i7h commented 2 years ago

A different error when trying to choose from the completion list after typing multibyte letter

[ERROR  ] /Users/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/nsh-0.4.2/src/main.rs: panicked at 'called `Result::unwrap()` on an `Err` value: RecvError', /Users/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/nsh-0.4.2/src/bash_server.rs:26:33
[ERROR  ] /Users/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/nsh-0.4.2/src/main.rs: panicked at 'assertion failed: self.is_char_boundary(n)', /Users/$USER/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/string.rs:1561:29
[ERROR  ] /Users/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/nsh-0.4.2/src/main.rs:    0:        0x101fabc18 - backtrace::capture::Backtrace::new::hba9adf1e5b3c7a91
   1:        0x101f727d8 - nsh::main::{{closure}}::h67739294c6afee12
   2:        0x102027e9d - std::panicking::rust_panic_with_hook::hae2b05f08a320721
   3:        0x102045c5c - std::panicking::begin_panic_handler::{{closure}}::h72d68d3a77e0b718
   4:        0x102045c27 - std::sys_common::backtrace::__rust_end_short_backtrace::h7c5e286792f94edb
   5:        0x102045be0 - _rust_begin_unwind
   6:        0x10205ed9f - core::panicking::panic_fmt::h1b194bb80d76fb10
   7:        0x10205ecf7 - core::panicking::panic::hdb9dddaff64fd68b
   8:        0x101f45674 - nsh::mainloop::Mainloop::select_completion::h070c0693897dce31
   9:        0x101f3a94a - nsh::mainloop::Mainloop::handle_key_event::h72f2fc3ed6d69a71
  10:        0x101f399ae - nsh::mainloop::Mainloop::handle_event::h98f98893dfe246aa
  11:        0x101f3602f - nsh::mainloop::Mainloop::run::hd7a071cbdcd9cbdc
  12:        0x101f6e6e2 - nsh::shell_main::ha315b12f85f157a9
  13:        0x101f71ff9 - nsh::main::h367ea8887b771698
  14:        0x101ecb2aa - std::sys_common::backtrace::__rust_begin_short_backtrace::hde4e21082195018a
  15:        0x101f88794 - _main

[ERROR  ] /Users/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/nsh-0.4.2/src/main.rs: panicked at 'called `Result::unwrap()` on an `Err` value: RecvError', /Users/$USER/.cargo/registry/src/github.com-1ecc6299db9ec823/nsh-0.4.2/src/bash_server.rs:26:33
nuta commented 2 years ago

Thanks for reporting the issue, @yu-ichiro! As you mentioned it's similar to #14, but I guess it's another wide-width character handling bug.