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

org.jcp.xml.dsig.internal.dom.Utils.parseIdFromSameDocumentURI throws StringIndexOutOfBoundsException when calling substring method

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b03
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        ADDITIONAL SYSTEM INFORMATION :
        Linux, jdk 8

        A DESCRIPTION OF THE PROBLEM :
        For the method org.jcp.xml.dsig.internal.dom.Utils.parseIdFromSameDocumentURI,
        the unit test we generated in the attached snapshot.

        Maybe you would think the input parameter is invalid, but we should consider all possible situations and deal all possible exceptions.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        This is the test case we generate
        @Test
          public void test_parseIdFromSameDocumentURI{
              java.lang.String string0 = "0xpointer(id(=G6^Wr*m81i?Ah{^PCS(@r8-/(bwu9;InjsXk882M&lb%)`f"; org.jcp.xml.dsig.internal.dom.Utils.parseIdFromSameDocumentURI(string0);
          }

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        do not throw StringIndexOutOfBoundsException
        ACTUAL -
        throw StringIndexOutOfBoundsException

        ---------- BEGIN SOURCE ----------
        public static String parseIdFromSameDocumentURI(String uri) {
                if (uri.length() == 0) {
                    return null;
                }
                String id = uri.substring(1);
                if (id.startsWith("xpointer(id(")) {
                    int i1 = id.indexOf('\'');
                    int i2 = id.indexOf('\'', i1+1);
                    id = id.substring(i1+1, i2);
                }
                return id;
            }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        public static String parseIdFromSameDocumentURI(String uri) {
                if (uri.length() == 0) {
                    return null;
                }
                String id = uri.substring(1);
                if (id.startsWith("xpointer(id(")) {
                    int i1 = id.indexOf('\'');
                    int i2 = id.indexOf('\'', i1+1);
                    if (i1 + 1 >= 0 && i2 <= id.length() && i2 - i1 - 1 >= 0) {
                        id = id.substring(i1+1, i2);
                    }
                }
                return id;
            }

        FREQUENCY : occasionally


          Attachments

            Issue Links

              Activity

                People

                Assignee:
                weijun Weijun Wang
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                9 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: