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

Big value of maxOccurs of element declaration causes StackOverflowError

    XMLWordPrintable

Details

    • b81
    • generic
    • generic
    • Verified

    Description

      Name: eaR10174 Date: 04/25/2002


       The following valid schema and valid xml document causes java.lang.StackOverflowError
         
      ------------------------------------test.xsd-----------------------------
      <?xml version="1.0"?>

      <xsd:schema
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns="test"
        targetNamespace="test">

           <xsd:element name="a" type="A"/>
           <xsd:complexType name="A">
                <xsd:sequence>
      <xsd:element name="b" type="xsd:string" maxOccurs="3000"/>
      </xsd:sequence>
           </xsd:complexType>

      </xsd:schema>
      -------------------------------------------------------------------------
      ------------------------------------test.xml-----------------------------
      <?xml version="1.0"?>
      <test:a
          xmlns:test="test"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="test test.xsd">
      <b>1</b>
      <b>2</b>
      </test:a>
      -------------------------------------------------------------------------

        Note the value of the attribute 'maxOccurs' is equal to 3000 which seems
      lead to the failure. If the value is set to less number the sample passes but
      spends innormal amount of time to parse the document (see table below).
        
        maxOccurs | time | status
       --------------------------------
         100 | 0m5.438s | passed
         1000 | 0m15.350s | passed
         2000 | 1m31.740s | passed
         3000 | 2m49.279s | failed (StackOverflowError)

      The time results were measured for
           - SUNW, Ultra-2; sparc; sun4u; RAM - 512M; 1 processor; Solaris 8

      configuration.

      The test has also failed on the following machines:

         - SUNW, Ultra-Enterprise; sparc; sun4u; RAM - 512M; 4 processors; Solaris 7
         - Dell PowerEdge 2300; Pentium II 350MHz; RAM -512M; 2 processors; WinNT 4.0 Server

      This bug is found in jaxp-1.2.0-fcs-b14-10_apr_2002 and affects the new JAXP TCK 1.2 tests

       api/xml_schema/structures/MGroup/compositor/compositor00101m/compositor00101m2.html

      Do the following steps to reproduce this bug:

      1. Save test.xsd and test.xml
      2. Save the following TestRun.java

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

      public class TestRun {

          public static void main(String [] args) {
              try {
                  // create and initialize the parser
                  SAXParserFactory spf = SAXParserFactory.newInstance();
                  spf.setNamespaceAware(true);
                  spf.setValidating(true);
                  SAXParser parser = spf.newSAXParser();

                  parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
                                     "http://www.w3.org/2001/XMLSchema");

                  File xmlFile = new File(args[0]);
                  parser.parse(xmlFile, new DefaultHandler());

                  System.out.println("Passed.");
              } catch (Exception e) {
                  e.printStackTrace();
                  System.out.println("Failed.");
              }
          }
      }
      -------------------------------------------------------------------------

      3. Set CLASSPATH

         % export CLASSPATH=.:$JAXP_HOME/dom.jar:$JAXP_HOME/dom.jar: $JAXP_HOME/sax.jar:$JAXP_HOME/jaxp-api.jar:$JAXP_HOME/xalan.jar: $JAXP_HOME/xercesImpl.jar

      4. Compile TestRun.java

         % javac TestRun.java

      5. Run the test

         % java -showversion TestRun test.xml


      I got the following result when I set the value of the attribute 'maxOccurs' to 3000:

      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)

      Exception in thread "main" java.lang.StackOverflowError
        at org.apache.xerces.impl.dtd.models.CMNode.firstPos(CMNode.java:96)
        at org.apache.xerces.impl.xs.models.XSCMBinOp.calcFirstPos(XSCMBinOp.java:136)
        at org.apache.xerces.impl.dtd.models.CMNode.firstPos(CMNode.java:97)
        at org.apache.xerces.impl.xs.models.XSCMBinOp.calcFirstPos(XSCMBinOp.java:136)
        at org.apache.xerces.impl.dtd.models.CMNode.firstPos(CMNode.java:97)
        at org.apache.xerces.impl.xs.models.XSCMBinOp.calcFirstPos(XSCMBinOp.java:136)
        at org.apache.xerces.impl.dtd.models.CMNode.firstPos(CMNode.java:97)
        at org.apache.xerces.impl.xs.models.XSCMBinOp.calcFirstPos(XSCMBinOp.java:136)
        at org.apache.xerces.impl.dtd.models.CMNode.firstPos(CMNode.java:97)
        at org.apache.xerces.impl.xs.models.XSCMBinOp.calcFirstPos(XSCMBinOp.java:136)
        at org.apache.xerces.impl.dtd.models.CMNode.firstPos(CMNode.java:97)
        at org.apache.xerces.impl.xs.models.XSCMBinOp.calcFirstPos(XSCMBinOp.java:136)
        at org.apache.xerces.impl.dtd.models.CMNode.firstPos(CMNode.java:97)
        at org.apache.xerces.impl.xs.models.XSCMBinOp.calcFirstPos(XSCMBinOp.java:136)
        ...

      ======================================================================
      ###@###.### 11/2/04 22:00 GMT

      Attachments

        Issue Links

          Activity

            People

              jsuttorsunw Jeff Suttor (Inactive)
              evgsunw Evg Evg (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: