Under Linux I attempted to read a bad JPEG 2000 file which resulted in a crash (glibc: double free or corruption). The following message is displayed, followed by a stack trace:
error: cannot decode code stream
NOTE: The same message is displayed in Windows, but a crash does not occur.
I traced trough ilLoadImage(), ilLoadJp2(), and ilLoadJp2F(). In ilLoadJp2F() there is a call to iLoadJp2Internal() which is followed by a call to jas_stream_close(). In iLoadJp2Internal(), if the call to jas_image_decode() fails then jas_stream_close() is called and the function returns. However, upon returning jas_stream_close() will get called a second time which leads to the crash.
Please see the attached patch which fixes this bug.