United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6404011 IllegalArgumentException: "Invalid ICC Profile Data" when reading certain JPEGs
JDK-6404011 : IllegalArgumentException: "Invalid ICC Profile Data" when reading certain JPEGs

Details
Type:
Bug
Submit Date:
2006-03-24
Status:
Resolved
Updated Date:
2011-01-19
Project Name:
JDK
Resolved Date:
2006-04-19
Component:
client-libs
OS:
windows_2003,linux
Sub-Component:
javax.imageio
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.2_18,5.0
Fixed Versions:

Related Reports
Backport:
Backport:
Backport:
Backport:

Sub Tasks

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

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
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



Hardware and Software, Engineered to Work Together