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

XML parser returns corrupt attribute value

XMLWordPrintable

    • b40
    • x86_64
    • windows_7

        FULL PRODUCT VERSION :
        java version "1.8.0_20"
        Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
        Java HotSpot(TM) Client VM (build 25.20-b23, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.1.7601]

        A DESCRIPTION OF THE PROBLEM :
        Parsing the XML contained in the sample program provided gives a wrong value "q" for the attribute a1. The correct value is "w".

        The problem depends on the &quote; value of the second attribute a2 and the buffer sizes used when parsing the XML. If a previous read stops after "...&q" then the last entity character "q" corrupts the string buffer of the previously read attribute a1. Therefore the attribute a1 returns the value "q" instead of "w".


        REGRESSION. Last worked in version 7u40

        ADDITIONAL REGRESSION INFORMATION:
        java version "1.8.0_20"
        Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
        Java HotSpot(TM) Client VM (build 25.20-b23, mixed mode, sharing)

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Simply run the program attached to this issue and see the output "q".
        "w" would be the correct output.



        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Attribute "a1" should have the value "w" not "q" as it is with Java 1.7 Update 40
        ACTUAL -
        Attribute "a1" has value "q".

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.io.ByteArrayInputStream;
        import javax.xml.parsers.DocumentBuilderFactory;
        import org.w3c.dom.Document;

        public class XMLParserBug {
            public static void main(String[] args) throws Exception {
                Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ChunkInputStream());
                System.out.println(d.getDocumentElement().getAttribute("a1"));
            }
            
            static class ChunkInputStream extends ByteArrayInputStream {
                ChunkInputStream() {
                    super("<element a1=\"w\" a2=\"&quot;&quot;\"/>".getBytes());
                }
           
                @Override
                public synchronized int read(byte[] b, int off, int len) {
                    return super.read(b, off, 9);
                }
            }
        }

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

        CUSTOMER SUBMITTED WORKAROUND :
        Change buffer sizes when reading the XML file. This may produce the same problem with other XMLs, since it depends on the XML structure and the buffer sizes.

              joehw Joe Wang
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: