United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6791502 IIOException "Invalid icc profile" on jpeg after update from JDK5 to JDK6
6791502 : IIOException "Invalid icc profile" on jpeg after update from JDK5 to JDK6

Details
Type:
Bug
Submit Date:
2009-01-08
Status:
Closed
Updated Date:
2011-03-07
Project Name:
JDK
Resolved Date:
2011-03-07
Component:
client-libs
OS:
windows_xp
Sub-Component:
javax.imageio
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:
7

Related Reports
Backport:

Sub Tasks

Description
FULL PRODUCT VERSION :
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) Client VM (build 10.0-b23, mixed mode, sharing)
---
java version "1.6.0_07"
Java(TM) SE Runtime Environment (build 1.6.0_07-b06)
Java HotSpot(TM) 64-Bit Server VM (build 10.0-b23, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP SP3 [Version 5.1.2600]
---
Linux 2.6.18.7-em64t SMP x86_64 GNU/Linux


A DESCRIPTION OF THE PROBLEM :
When reading a JPEG-File, an IIOException is thrown. The file can be opened by other applications, in browsers and can be read by Java when using an older JDK5:

java version "1.5.0_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) Server VM (build 1.5.0_08-b03, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
ImageIO.read(new File("C:\\4250252101840_b24a3a71d3116db3eead8c20753ea629.jpg"));

The file which produces the error can be provided upon request.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
BufferedImage is created.
ACTUAL -
IIOException is thrown.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
javax.imageio.IIOException: Invalid icc profile: bad sequence number
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.readImageHeader(Native Method)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.readNativeHeader(JPEGImageReader.java:560)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.checkTablesOnly(JPEGImageReader.java:315)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.gotoImage(JPEGImageReader.java:437)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.readHeader(JPEGImageReader.java:553)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(JPEGImageReader.java:931)
	at com.sun.imageio.plugins.jpeg.JPEGImageReader.read(JPEGImageReader.java:915)
	at javax.imageio.ImageReader.read(ImageReader.java:923)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public static void main(String args[]) {
	try {
		ImageIO.read(new File("C:\\4250252101840_b24a3a71d3116db3eead8c20753ea629.jpg"));
	} catch (IOException e) {
		e.printStackTrace();
	}
}

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

Release Regression From : 5
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

                                    

Comments
SUGGESTED FIX

http://sa.sfbay.sun.com/projects/java2d_data/7/6791502.0
                                     
2009-01-30
EVALUATION

This problem (icc profile reading failure) was present in 5.0 and former releases
but was masqueraded by extra JNI calls (made by RELEASE_ARRAY).
Note that  -Xcheck:jni flag makes this problem visible in 5.0:

C:\work\bugs\6791502>5.0u17\windows-i586\jre\bin\java -Xcheck:jni Test test.jpg
Test file: test.jpg
Warning: Calling other JNI functions in the scope of Get/ReleasePrimitiveArrayCritical or Get/ReleaseStringCritical
Warning: Calling other JNI functions in the scope of Get/ReleasePrimitiveArrayCritical or Get/ReleaseStringCritical
Warning: Calling other JNI functions in the scope of Get/ReleasePrimitiveArrayCritical or Get/ReleaseStringCritical
FATAL ERROR in native method: JNI call made with exception pending
        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:1286)
        at Test.main(Test.java:13)

The fix for CR 4528643 (6.0b83) made this problem more visible: after this fix the IIOEXception
  which was thrown by read_icc_profile is not consumed anymore and this is reason of observed
  change in the reader behavior.

So, there are two separate problems:

1) Method read_icc_profile() may throw an IIOException if there are some problem
     with profile chunks (wrong numeration or missed chunks, for example). We should
     handle this exception before performing invocation of setImageData() in order to
     avoid the JNI state corruption.

2) In particular case of given image we should be more tolerant to incorrect profile
    chunks numeration: in case of single chunk we probably can ignore incorrect chunk
    number without any risk.
                                     
2009-01-29



Hardware and Software, Engineered to Work Together