United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-5098176 : Some PNGs fail to load with ImageIO

Details
Type:
Bug
Submit Date:
2004-09-07
Status:
Resolved
Updated Date:
2006-03-22
Project Name:
JDK
Resolved Date:
2006-03-22
Component:
client-libs
OS:
windows_xp,windows_2000
Sub-Component:
javax.imageio
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.4.2
Fixed Versions:

Related Reports
Backport:
Backport:

Sub Tasks

Description
Name: rmT116609			Date: 09/07/2004


FULL PRODUCT VERSION :
java version "1.4.2_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04)
Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode)

java version "1.5.0-rc"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-rc-b63)
Java HotSpot(TM) Client VM (build 1.5.0-rc-b63, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
An Exception occurs when using ImageIO to load some PNGs. Seems much more common with greyscale PNGs - I have a lot and it happens on about 5-10%. From multiple sources too (downloaded from internet). I haven't been able to create problem input files locally, however.

Looks identical to bug-id 4463483. The line numbers are different, but looks otherwise identical.

Every other image viewer I have can view the same files without any problem.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
This is all that's required:
ImageIO.read(file);

Where "file" is a path to a PNG file.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
  To get a java.awt.Image object
ACTUAL -
An exception is thrown


ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.IllegalArgumentException: LUT has improper length!
	at javax.imageio.ImageTypeSpecifier$Indexed.<init>(ImageTypeSpecifier.java:866)
	at javax.imageio.ImageTypeSpecifier.createIndexed(ImageTypeSpecifier.java:955)
	at com.sun.imageio.plugins.png.PNGImageReader.getImageTypes(PNGImageReader.java:1463)
	at com.sun.imageio.plugins.png.PNGImageReader.readImage(PNGImageReader.java:1348)
	at com.sun.imageio.plugins.png.PNGImageReader.read(PNGImageReader.java:1530)
	at javax.imageio.ImageIO.read(ImageIO.java:1400)
	at javax.imageio.ImageIO.read(ImageIO.java:1286)
	at slides.test.main(test.java:11)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package slides;

import java.awt.Image;
import java.io.File;
import javax.imageio.ImageIO;

public class test {
    public static void main(String[] args) {
        File file = new File(args[0]);
        try {
            Image img = ImageIO.read(file);
        } catch (Exception E) {
            E.printStackTrace();
        }
    }
}

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

CUSTOMER SUBMITTED WORKAROUND :
Re-saving problem input images in an image editor works - the file then loads/displays properly via ImageIO. However, this isn't possible for remote images, as well as being tedious for the end-user.
(Incident Review ID: 301679) 
======================================================================

                                    

Comments
EVALUATION

Not for tiger.
###@###.### 2004-09-16
                                     
2004-09-16
EVALUATION

The problem here is that PNGImageReader fails to create the
 instance of the ImageTypeSpecifier corresponding to the indexed
 PNG image if the length of the image palette in smaller than
 2^bitDepth.

 The spec of createIndexed() method demands the exact equality
 of the palette length and number of possible palette entries
 (2^bitDepth).
 However, this demand conflicts with the PNG image format spec
 that says that situation when the palette is smaller than 2^bitDepth
 is legal. This is extract from the PNG spec:
  
 The number of palette entries must not exceed the range that
 can be represented in the image bit depth (for example, 2^4 = 16
 for a bit depth of 4). It is permissible to have fewer entries
 than the bit depth would allow. In that case, any out-of-range
 pixel value found in the image data is an error.

 (http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html#C.PLTE) 

 To avoid this limitation we can create new palette arrays of the
 appropriate power of 2 size. This arrays are padded with last
 value from original arrays in order to avoid appearance of colors
 that are not exist in original palette.
                                     
2006-03-01



Hardware and Software, Engineered to Work Together