AuburnSounds / gamut

Image encoding and decoding library for D. Detailed layout control. Experimental codec QOIX.
Boost Software License 1.0
41 stars 2 forks source link

Please provide a way to gracefully fail for corrupt jpegs #46

Closed gizmomogwai closed 1 year ago

gizmomogwai commented 1 year ago

First of all thanks for this excellent library. I was able to replace imagefmt quickly with your library (which supports more imageformats and variants.

While testing I encountered assert(false calls in stop_decoding (e.g. trying to load a jpeg from an empty file). It would be great if the error handling could be done on application level and the load in this case would return an invalid image.

I created a local patch for that (by removing the assert and replacing all calls to stop_decoding with stop_decoding and a return, but I am not sure that this is the best way.

p0nce commented 1 year ago

Hello,

Normally all failed loading should fail with isError, so your suggestion is exactly what is intended to happen.

So this is a bug in the decoder if an empty file asserted (which is an input error, not a logic error).

p0nce commented 1 year ago

JPEG loader should now gracefully handle bad input, though only fuzzing will tell. Probably leaks a bit of memory on bad input. Use 2.1.2+

p0nce commented 1 year ago

This is 2bc035c4b4384e460ffad7e9fa32b24918648e0d

gizmomogwai commented 1 year ago

Wow .. that was fast, will give it a try!

gizmomogwai commented 1 year ago

Works for my usecase (empty jpg), thanks a lot!

gizmomogwai commented 1 year ago

fuzzing is always fun :)

p0nce commented 1 year ago

Pleasure. Let me know if you identify annoying things in the library.