JDK-6404011 : IllegalArgumentException: "Invalid ICC Profile Data" when reading certain JPEGs
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 1.4.2_18,5.0
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux,windows_2003
  • CPU: x86
  • Submitted: 2006-03-24
  • Updated: 2011-01-19
  • Resolved: 2006-04-19
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6
1.4.2_20-revFixed 6 b81Fixed
Description
FULL PRODUCT VERSION :
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
(Re-)produced on 2 Debian systems:
Linux metis 2.6.8-2-686-smp #1 SMP Thu May 19 17:27:55 JST 2005 i686 GNU/Linux
Linux phoebe.liland.org 2.6.8-2-686-smp #1 SMP Tue Aug 16 12:08:30 UTC 2005 i686 GNU/Linux

.. and one Gentoo system:
Linux halley 2.6.15-gentoo-r1 #1 SMP PREEMPT Wed Jan 25 13:59:38 CET 2006 i686 Intel(R) Pentium(R) M processor 2.00GHz GenuineIntel GNU/Linux


EXTRA RELEVANT SYSTEM CONFIGURATION :
Sample image file is provided here:
http://member.ycn.com/~emu/keiler16.jpg

I would like to attach this file to the bug report. However since this does not seem to be possible, I will keep it available at the given URL as long as possible.

A DESCRIPTION OF THE PROBLEM :
javax.imageio.ImageIO.read(ImageInputStream stream)  throws
an IllegalArgumentException for certain JPEG images. The error message complains about an "Invalid ICC Profile". Other programs (editors/viewser) report no problems when reading these images.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. download image from
http://member.ycn.com/~emu/keiler16.jpg
2. open with ImageIO.read(..) method

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A BufferedImage object should be created from the given image data.
ACTUAL -
IllegalArgumentException is thrown.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.IllegalArgumentException: Invalid ICC Profile Data
        at java.awt.color.ICC_Profile.getInstance(ICC_Profile.java:753)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.setImageData(JPEGImageReader.java:596)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImageHeader(Native Method)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.readNativeHeader(JPEGImageReader.java:554)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly(JPEGImageReader.java:309)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage(JPEGImageReader.java:431)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.readHeader(JPEGImageReader.java:547)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:880)
        at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:864)
        at javax.imageio.ImageIO.read(ImageIO.java:1400)
        at javax.imageio.ImageIO.read(ImageIO.java:1322)
...
 

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.imageio.ImageIO;
import java.io.*;

public class ImageTest {
  public static void main(String[] args) throws IOException {
    ImageIO.read(new File("keiler16.jpg"));
  }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
removing metadata from JPEG with a tool like jpegoptim (linux) or purejpeg (windows)

Comments
EVALUATION The root of the problem is corrupted color profile embedded to the jpeg image. Some native tools (like Adobe Photoshop) failed to use it as soon as the java ICC_Profile. The fix idea is to catch IllegalArgumentException which is thrown by ICC_Profile and handle image without taking into account invalid color profile.
2006-04-05

EVALUATION This is related to 6195301: Malformed serial form of the ICC profile crashes RMI server which is "fixed" in mustang. Previously on most systems that bug would cause a crash. Now that is intercepted and IllegalArgumentException is thrown. This is an unchecked exception and we at least ought to catch it and turn it into an IOException. But in this case we may be could just swallow the exception and ignore the bad profile. It does appear to be a bad profile - its claimed length is -128, but its also possible we are reading the wrong data. JAI's JPEG plugin reads the image without complaint, and experiment shows that simply ignoring the profile allows us to display the image in mustang too. I think there's an argument that 6195301 was not a full fix.
2006-03-24