OSS-fuzz #475335810
The problem here is to do with the disjointed way we have to work when
using the OpenJPEG JPX decoder. We send a spec_op to the device to say
that we've opened a filter, then we pass the data along, then (normally)
we send a 'end' spec_op. Finally, when the filter is closed, we send
a 'NULL'.
All of this is done using a supplied interpreter level function.
The problem here is that we abort the JPX decoding without ever
sending any data. This means we leave the device with the flag set to
expect JPX data.
We then get a totally different image, which is not JPX encodded, and
because the flag is set we start up the JPX writer when we receive data.
But because the image data isn't JPX encoded, we never hit the end of
data so we never send the spec_op to terminate it.
(this is what I mean by the usage being disjointed).
In this commit, when releasing the JPX filter just terminate the JPX
PassThrough, even if we haven't ever sent any data.
I also checked the DCT decoder; that works differently (better) and is
not affected in the same way.