kamiyaa / joshuto

ranger-like terminal file manager written in Rust
https://crates.io/crates/joshuto
GNU Lesser General Public License v3.0
3.41k stars 151 forks source link

Crash when previewing a plaintext file with control characters #284

Open adtac opened 1 year ago

adtac commented 1 year ago

I accidentally piped control characters to a file and tried to preview it and this crashed joshuto. Here's a minimal 2-byte reproducer:

$ echo 1b0a | xxd -r -p >foo
$ file --dereference --brief --mime-type -- foo
text/plain

I have cat as the preview for text/plain. Open joshuto and navigate to that file, the program will freeze and crash.

0x1b is ^[ (escape). I couldn't reproduce the bug without the newline at the end. I'm not sure if this happens with other control characters. It might be worth it to fuzz test joshuto previews?

kamiyaa commented 1 year ago

Awesome! Thanks for the bug report. I'll look into it and create a fix :+1: