Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4991647

PNGMetadata.getAsTree() sets bitDepth to invalid value

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 1.4.0
    • client-libs
    • b26
    • x86
    • windows_2000



        Name: cc94850 Date: 02/09/2004


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

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

        A DESCRIPTION OF THE PROBLEM :
        When trying to get the metadata as tree, the first call of the getAsTree() method returns a valid PNGMetadata tree. After setting the metadata from this tree with the setFromTree() method, the metadata object is still intact(node information is correctly stored in the PNGMetadata object). When trying to retreive the metadata as tree again ( getAsTree() ) the returned tree is invalid (bitDepht value is corrupted).

        The error is caused by the PNGMetadata.getNativeTree() method:
         IHDR_node.setAttribute("bitDepth", Integer.toString(IHDR_bitDepth));
        should be:
         IHDR_node.setAttribute("bitDepth", IHDR_bitDepths[IHDR_bitDepth]);


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        -create an empty, new PNGMetadata object
        -call getAsTree() method
        -call setFromTree() method
        -call getAsTree() method
        -call setFromTree() method

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        bitDepht should have been set to 8
        ACTUAL -
        bitDepht was set to 3 instead of 8

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        javax.imageio.metadata.IIOInvalidTreeException: Illegal value for attribute bitDepth!
        at com.sun.imageio.plugins.png.PNGMetadata.fatal(PNGMetadata.java:1076)
        at com.sun.imageio.plugins.png.PNGMetadata.getEnumeratedAttribute(PNGMetadata.java:1179)
        at com.sun.imageio.plugins.png.PNGMetadata.getEnumeratedAttribute(PNGMetadata.java:1187)
        at com.sun.imageio.plugins.png.PNGMetadata.mergeNativeTree(PNGMetadata.java:1243)
        at com.sun.imageio.plugins.png.PNGMetadata.mergeTree(PNGMetadata.java:1217)
        at javax.imageio.metadata.IIOMetadata.setFromTree(IIOMetadata.java:705)
        at TestCase.main(TestCase.java:54)


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.awt.image.ColorModel;
        import java.awt.image.SampleModel;
        import java.util.Iterator;

        import javax.imageio.ImageIO;
        import javax.imageio.ImageTypeSpecifier;
        import javax.imageio.ImageWriter;
        import javax.imageio.metadata.IIOMetadata;

        import org.w3c.dom.Node;

        import com.sun.imageio.plugins.png.PNGMetadata;

        /*
         * Created on 30.01.2004
         */

        /**
         * @author Beskid Lucian Cristian
         */
        public class TestCase {

        public static void main(String[] args) {

        // getting the writer for the png format
        Iterator iter = ImageIO.getImageWritersByFormatName("png");
        ImageWriter writer = (ImageWriter)iter.next();

        // creating a color model
        ColorModel colorModel= ColorModel.getRGBdefault();

        // creating a sample model
        SampleModel sampleModel = colorModel.createCompatibleSampleModel(640, 480);

        // creating a default metadata object
        IIOMetadata metaData = writer.getDefaultImageMetadata( new ImageTypeSpecifier(colorModel, sampleModel), null);

        if (metaData instanceof PNGMetadata){
        System.out.println("Assumption that this is a PNGMetadata object is correct.");

        String formatName = metaData.getNativeMetadataFormatName();

        // first call
        Node metaDataNode = metaData.getAsTree(formatName);
        try {
        metaData.setFromTree(formatName, metaDataNode);
        } catch (Exception ex) {
        ex.printStackTrace();
        }

        // second call (bitdepht is already set to an invalid value)
        metaDataNode = metaData.getAsTree(formatName);

        // here an exception will occur because of the invalid bit depht
        try {
        metaData.setFromTree(formatName, metaDataNode);
        } catch (Exception ex) {
        ex.printStackTrace();
        }
        }
        }
        }

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

        CUSTOMER SUBMITTED WORKAROUND :
        No workaround because the getNativeTree() method is private.
        (Incident Review ID: 236471)
        ======================================================================

              mcherkas Mikhail Cherkasov (Inactive)
              campbell Christopher Campbell (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: