torum / Image-viewer

A cross-platform, simple and minimum, yet configurable photo viewer/slideshow/digital signage app for Windows, Linux, and Mac.
https://torum.github.io/Image-viewer/
MIT License
92 stars 11 forks source link

Crash when extension does not match file type #19

Closed username115 closed 1 year ago

username115 commented 2 years ago

When attempting to open an image file where the extension indicates a particular file type, but the file is of a different image type, the program crashes. When fullscreened, there is no way to exit the program without sending it a console interrupt or kill command (at least in Linux).

For example, if an image is opened that has a png extension, but the headers indicate JPEG image data, JFIF standard 1.01 (using the file command on Linux), the following is printed in the console, and no image displays:

TApplication.HandleException Wrong image format

With a stack trace that includes only hexadecimal values (not included because I do not know what information it contains)

Most image viewer software will use the extension only to indicate if it should try to open the file, while the header information is used to determine how to interpret the information.

username115 commented 2 years ago

Since posting this, I realized I was apparently using the version that was already built and packaged in the repository (under files/bin/executable), and have since built the latest master.

The issue is still present, but the symptoms are not the same. In the latest master, instead of causing a hang when in fullscreen, an error message is displayed in place of the image, but the program is still responsive. Windowed mode behaves the same as fullscreen now as well.

torum commented 1 year ago

I'm really sorry, that I missed this.. I do much appreciate your reporting. Like you pointed out, the binary file is outdated.. like from 2018.

As for the behavior of opening an image, ImageViewer doesn't do much except ''Image1.Picture.LoadFromFile("FilePath");'' If the Image component says it can't open, there isn't much I can do. I'm sure there are hundreds of other third-party components out there that handle this kind of situation much better, but I don't like to depend on third-party libraries for ImageViewer.

So... Thank you very much for reporting though.