tannerhelland / PhotoDemon

A free portable photo editor focused on pro-grade features, high performance, and maximum usability.
https://photodemon.org
Other
1.38k stars 201 forks source link

[BUG] - XBM images make PhotoDemon freeze #544

Closed manfromarce closed 6 months ago

manfromarce commented 6 months ago

Version information

PhotoDemon 9.2 nightly build 277, Windows 11 22621.3235

Describe the bug

PhotoDemon doesn't list XPM and XBM formats in the Open dialog but tries to open them if you drag and drop them in the window. However, while XPM are loaded correctly, XBM files block the app which waits indefinitely and becomes unresponsive. If you try to click something, the window becomes white and you get the classic Windows message "PhotoDemon is not responding" offering the option to wait or kill the process. Unfortunately, if the file was dropped, Windows Explorer hangs too until PhotoDemon is forcibly closed, because it's like the drag-drop operation never completes properly.

How can I reproduce the bug?

  1. It occurs with any XBM image, it isn't a common format but you can draw something on GIMP (or load an existing image) and export to XBM
  2. Drag and drop the XBM file into PhotoDemon
  3. PhotoDemon becomes unresponsive

Expected behavior

This format should be loaded properly or an error message should be displayed if it is not supported, like in other cases.

Debug logs

In all cases it seems that the application hangs on "Invoking FreeImage_LoadUInt...", e.g.: DebugReport_1.log

tannerhelland commented 6 months ago

Thank you for filing this issue, @manfromarce . I have confirmed the same crash here, on basically all XBM images I tested.

When PhotoDemon doesn't recognize an image file, it passes it to the 3rd-party FreeImage library as a "last chance" effort for esoteric file formats. FreeImage claims to support XBM and XPM files but clearly its internal support is badly broken for XBM.

Rather than prevent XBM files from loading at all, I think I can write a quick little XBM loader myself. I will try to get to this in the coming days to see if I can solve the current crash.

I will report back when I have something to test. Thank you again.

tannerhelland commented 6 months ago

I have now removed FreeImage as a possible XBM importer for PhotoDemon, and instead written a custom XBM importer from scratch. XBM images should no longer crash when loading.

I have downloaded some large XBM collections (currently batch processing in the background) as additional testing, but I'd also welcome help trying any XBM files that crashed previously. Thank you in advance, and thank you again for catching and reporting this problem!

hi5 commented 6 months ago

I tested it earlier with a sample file from https://filesamples.com/formats/xbm which indeed made PD crash, now it loads fine.

Also the case with the sample file(s) from https://filesamples.com/formats/xpm

manfromarce commented 6 months ago

Thank you @tannerhelland for the quick implementation, the files I had tested now load properly. xbm.zip If I find other XBM files which cause issues I'll certainly share them, but it seems solved now.

However, while dropping images into PhotoDemon I have noticed a minor usability issue: if you accidentally drop a file onto the "quick start" buttons / text rather than on blank space, it seems to accept the drop but doesn't load the file. The same occurs on the left and right panels, while works properly on the canvas, images tab strip and layers panel. Do you think it would be possible to accept file drop in the whole window? Thank you in advance.

tannerhelland commented 6 months ago

Thank you @hi5 and @manfromarce for testing XBM support! I really appreciate the extra help. I am satisfied that XBM support is OK now, so I will go ahead and close this issues.

@manfromarce - it is difficult for me to track unrelated issues inside a thread, so I will copy+paste your notes on dropping images into a new issue. Thank you for mentioning this to me!