Closed SamStephens closed 17 hours ago
Thanks for reporting!
This seems to be a perfectly valid JPEG. It contains a DNL ("define number of lines") marker. These are so rare I never seen one before in the wild...
I also think you are right about the code not handling a case it should. I'll create a fix and use your sample file as a test case.
Should be fixed in the latest snapshot. I'll try to make a bug fix release soon.
Thanks @haraldk , much appreciated.
Describe the bug
I have a JPEG file that, when you try and read the metadata, has the error
java.lang.ClassCastException: class com.twelvemonkeys.imageio.plugins.jpeg.Unknown cannot be cast to class com.twelvemonkeys.imageio.plugins.jpeg.Application
.It's unclear to me whether the JPEG is corrupt or not, but I think regardless of whether it is, this is still a bug.
Version information
The version of the TwelveMonkeys ImageIO library in use. 3.12.0
The exact output of
java --version
(orjava -version
for older Java releases).Extra information about OS version, server version, standalone program or web application packaging, executable wrapper, etc. Please state exact version numbers where applicable.
My stack trace is from a unit test for a Gradle based project running on Ubuntu on WSL2.
To Reproduce Steps to reproduce the behavior:
From a project including com.twelvemonkeys.imageio:imageio-jpeg:3.12.0, run the unit test I provide with my example file available as a resource.
Expected behavior
Either the metadata to be provided, or if the JPEG is corrupt, an exception indicating such.
Example code Preferably as a failing JUnit test, or a standalone program with a
main
method that showcases the problem.Sample file(s)
Stack trace
Screenshots
N/A
Additional context
I think that the root cause is that the metadata class does not actually have handling for the Unknown segment type (I don't know this code so I could easily be mistaken).
The actual error is from the cast to
com.twelvemonkeys.imageio.plugins.jpeg.Application
in https://github.com/haraldk/TwelveMonkeys/blob/34c9b9b4b51f477a816dda1869db73b5c723e5de/imageio/imageio-jpeg/src/main/java/com/twelvemonkeys/imageio/plugins/jpeg/JPEGImage10Metadata.java#L268-L274I believe the Unknown segment is created in this default case when reading segments https://github.com/haraldk/TwelveMonkeys/blob/34c9b9b4b51f477a816dda1869db73b5c723e5de/imageio/imageio-jpeg/src/main/java/com/twelvemonkeys/imageio/plugins/jpeg/Segment.java#L97-L98