JPEG decoding crashes if HeapBlock fails to allocate enough memory

#1

JPEG decoding crashes if HeapBlock fails to allocate enough memory. The HeapBlock doesn’t throw an exception, it just returns nullptr.

Image::BitmapData.data == nullptr and getLinePointer returns null and then when it tries to write the image data it crashes.

Could you make it like this:

                    const Image::BitmapData destData (image, Image::BitmapData::writeOnly);
                    if (destData.data == nullptr)
                        return {};
0 Likes

#2

There’s already an assertion that protects against this in the BitmapData constructor.

If you’ve exhausted your memory then there’s not much you can do about it. Sure, this allocation won’t cause a crash, but then an allocation elsewhere will fail and you’ll be back into uncharted waters.

1 Like