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

Data corruption in saxparser, chars outside XML passed to sax.helpers.DefaultHandler.characters()

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 1.1, 6u5
    • Fix Version/s: 9
    • Component/s: xml

      Description

      // Test program to demonstrate a data corruption error in SAXParser.
      //
      // 2008-06-18 Christian d'Heureuse, ###@###.###, www.source-code.biz
      //
      // Environments tested in which the error occurs:
      // 1.6.0_10-beta-b25 Windows XP SP2 (includes Xerces 2.6.2)
      // 1.6.0_06-b02 Windows XP SP2 (includes Xerces 2.6.2)
      // 1.6.0_05-b13 Windows XP SP2 (includes Xerces 2.6.2)
      //
      // Environments tested in which the error does not occur:
      // 1.6.0_10-beta-b25 Windows XP SP2 with Xerces snapshot 2008-06-15 (file xml-parser-gump-15062008.jar)
      // 1.6.0_10-beta-b25 Windows XP SP2 with Xerces 2.9.1
      // 1.6.0_10-beta-b25 Windows XP SP2 with Xerces 2.8.1
      // 1.5.0_10-b03 Linux (includes Xerces 2.6.2)
      //
      // (Note that the Xerces JAR file must be copied into the lib/endorsed
      // directory, in order to override the Xerces classes of the Java library.
      // It's not sufficient to include the JAR file in the classpath.)

      import java.io.File;
      import javax.xml.parsers.SAXParser;
      import javax.xml.parsers.SAXParserFactory;
      import org.xml.sax.helpers.DefaultHandler;

      public class SaxParserError extends DefaultHandler {

      private static final String inputFileName = "SaxParserError.xml";
      private static final String testPattern = "column-data";

      public static void main (String args[]) throws Exception {
         SAXParser saxParser;
         SAXParserFactory factory = SAXParserFactory.newInstance();
         factory.setValidating(false);
         saxParser = factory.newSAXParser();
         saxParser.parse(new File(inputFileName), new SaxParserError());
         System.out.println ("OK, no error detected."); }

      public void characters(char buf[], int offset, int len) {
         String s = new String(buf, offset, len);
         if (s.contains(testPattern)) {
            System.out.println ("Data corruption error detected.");
            System.exit (9); }}

      } // end class SaxParserError
      Regression from 1.5, broken in 6u1 - 6u10


      I have found a data corruption error in SAXParser.

      A test program and the XML data file to reproduce the error is at:
      http://www.source-code.biz/snippets/java/saxParserError/

      The error occurs with the SAXParser version included in JDK 1.6.0_10-beta-b25 (and other 1.6 versions), but not with the SAXParser of Xerces 2.9.1. It also does not occur with JDK 1.5.

      The XML file used to reproduce this error is relatively big (86k). We tried to reduce it's size, but small changes on the XML file change the symptoms of the error.

      The error is that characters from outside the text content of the XML elements are passed through org.xml.sax.helpers.DefaultHandler.characters().
      Fragments from the XML file structure occur as element content text character

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              joehw Joe Wang
              Reporter:
              rlewis Roger Lewis (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: