Fredy Fredy - 1 month ago 5x
Java Question

javax.imageio.IIOException: Invalid icc profile: duplicate sequence numbers

I'm trying to read a JPEG file, but when I try this:

InputStream input = new URL("").openStream();
try {;
System.out.println("Image loaded.");
} catch (Throwable e) {
} finally {

I receive the following exception:

javax.imageio.IIOException: Invalid icc profile: duplicate sequence numbers
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImageHeader(Native Method)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readNativeHeader(
at com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly(
at com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage(
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readHeader(
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(

This exception occurs only with this image:

I tested both the JDK 7 and 8, both have the error.
Do you have any suggestions on how I can read the image? It's possible to adjust the icc profile?


As the error message suggests, the ICC_PROFILE segments in your JPEG file contains duplicate sequence numbers. This means that the software that wrote it, is broken in some way. However, the image data should still be readable, even though the colors might not look exactly as they should.

Because JFIF (the JPEG File Interchange Format) has limited segment size, large ICC profiles must be split over multiple segments. The specification says that the ICC profile should be stored in multiple APP2 segments, and that each segment must start with the null-terminated string ICC_PROFILE, followed by a single unsigned byte sequence number and a total count.

My TwelveMonkeys ImageIO JPEG plugin is able to read your image, even if the ICC profile segments are broken. It will issue a warning (if you have registered an IIOReadWarningListener) telling you that the ICC profile will be ignored. I have tested, and it works fine with your JPEG file. You shouldn't need to change any code, just add the required dependencies (from the link above) and it should work.

twelvemonkey plugin 3.2.1 in maven repository

You could probably also fix the indexes/counts of the profile with a hex editor, if you know what you are doing. :-) But from experience, the profiles of such images may not match the color data of the image anyway, so you might be out of luck.