atanunq / viu

Terminal image viewer with native support for iTerm and Kitty
MIT License
2.5k stars 54 forks source link

Can't open tiny (<20 byte) files #77

Closed DavidBuchanan314 closed 3 years ago

DavidBuchanan314 commented 3 years ago

For tiny files, the format guesser reads off the end of the file, causing a panic: https://github.com/atanunq/viu/blob/8a2324a94cb1e53511094f2675b9c27ea7e273d4/src/app.rs#L128-L130

An example of such a tiny (15 byte) file is as follows (an 8x8 PBM bitmap):

P4
8 8
AAAAAAA

(note, there are 7 A's, the 8th byte of bitmap data is the trailing newline)

The file should look like this, when viewed in GIMP (or other viewer):

image

Imagemagick can also handle it as an input file.

Padding the file with zeroes, up to 20 bytes, allows viu to open the file correctly.