JDK-6517427 : GIF Reader throws IIOException when reading a Indexed GIF image with an embedded color profile
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 1.4.2,6,6u15,6u23
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2007-01-25
  • Updated: 2012-10-01
  • Resolved: 2011-03-07
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.
JDK 6 JDK 7
6u24-revFixed 7 b10Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Description
I am reading the attached image using ImageIO's GIF Reader and GIF Reader is throwing the following exception -

Exception in thread "main" javax.imageio.IIOException: Unexpected block type 0!
at com.sun.imageio.plugins.gif.GIFImageReader.readMetadata(GIFImageReader.java:722)
at com.sun.imageio.plugins.gif.GIFImageReader.read(GIFImageReader.java:794)
at javax.imageio.ImageReader.readAll(ImageReader.java:1050)
at MetadataViewer.main(MetadataViewer.java:82)

The attached image is a GIF image having an embedded color profile. This is reproducible on JDK6/7 on all platforms. Toolkit API is able to read the image properly. 

Run the attached tests as follows -
java KannanImageIOTest <img>
java MetadataViewer <img>

Comments
EVALUATION The gif file in question is uses application extension "ICCRGBG1012" that is described here: http://www.color.org/wpaper2.html. However, implementation of this extension seems to be not completely valid from the spec-gif89a point of view. Namely, this spec states that size of application block should be 11 (the sum of length of application ID field and length of auth code field) and application extension data should be represented as subsequent data sub-blocks. Contrary to this, this extension uses the rest of application extension block to store data. The ImageIO GIF reader does not ready to meet application data inside application block and tries to extract it form wrong position that leads to described failure of decoding routine. To solve this problem I suggest to check declared length of application extension block and treat rest of application extension block content (i.e. everything else than application ID and auth code) as an application extension data. *** (#1 of 1): [ UNSAVED ] ###@###.###
25-01-2007