JDK-6359303 : ImageReader throws an exception on certain GIF files
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.imageio
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2005-12-06
  • Updated: 2011-03-07
  • 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 7
7 b10Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Server VM (build 1.5.0-b64, mixed mode)

(confirmed also in JDK 1.4.2_04 and 1.4.2_06)

ADDITIONAL OS VERSION INFORMATION :
Linux XX 2.4.24 #7 SMP XX  i686 GNU/Linux

(confirmed also on Mac OSX)

A DESCRIPTION OF THE PROBLEM :
The ImageIO ImageReader throws an exception in the .read() method on some types of GIF images.

A sample file can be found at

ftp://ftp.berlios.de/pub/digilib/babylon_funny.gif

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Invoke ImageReader.read() on a special GIF image (e.g. with the provided test program)

A sample image file can be found at

ftp://ftp.berlios.de/pub/digilib/babylon_funny.gif



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
the reader loads the image
ACTUAL -
the reader throws an exception

ERROR MESSAGES/STACK TRACES THAT OCCUR :
javax.imageio.IIOException: Unexpected block type 51!
        at com.sun.imageio.plugins.gif.GIFImageReader.readMetadata(GIFImageReader.java:721)
        at com.sun.imageio.plugins.gif.GIFImageReader.read(GIFImageReader.java:954)
        at javax.imageio.ImageReader.read(ImageReader.java:919)
        at ReadImgTest.main(ReadImgTest.java:43)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.*;
import java.util.*;
import java.awt.image.*;
import javax.imageio.*;
import javax.imageio.stream.*;

public class IIO {

	public static void main(String[] args) {
		File f = new File(args[0]);
		ImageInputStream iis = null;
		try {
			iis = new FileImageInputStream(f);
		} catch (FileNotFoundException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		Iterator i = ImageIO.getImageReaders(iis);
		ImageReader r = (ImageReader) i.next();
		r.setInput(iis);
		try {
			BufferedImage img = r.read(0);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}


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

Comments
EVALUATION This problem was fixed as part of fix for CR 6517427.
13-03-2007

EVALUATION The gif file in question is uses application extension "Adobe". Note that implementation of this application 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 bytes (the sum of 8 bytes per application ID field and 3 bytes per auth code field). However, this extension writes 10 bytes length application extension block. The ImageIO GIF reader is not ready to meet application extension block shorter that it is declared in the spec: it reads one extra byte form subsequent data sub-block and starts reading application data from 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 compose application ID and auth code fields using available data only.
25-01-2007