changeset 1510:c75d23b3a8ff

8232014: Expand DTD support Reviewed-by: lancea, dfuchs, mschoene, rhalade, aefimov
author joehw
date Sat, 11 Jul 2020 20:36:43 +0100
parents 7b4278b4a56f
children 7bd194c33dfa
files src/com/sun/org/apache/xerces/internal/impl/XMLDTDScannerImpl.java src/com/sun/org/apache/xerces/internal/impl/XMLScanner.java src/com/sun/org/apache/xerces/internal/impl/dtd/DTDGrammar.java
diffstat 3 files changed, 21 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/sun/org/apache/xerces/internal/impl/XMLDTDScannerImpl.java	Wed Apr 15 14:59:36 2020 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/XMLDTDScannerImpl.java	Sat Jul 11 20:36:43 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
  */
 
 /*
@@ -67,6 +67,7 @@
  * @author Eric Ye, IBM
  *
  * @version $Id: XMLDTDScannerImpl.java,v 1.8 2010-11-01 04:39:41 joehw Exp $
+ * @LastModified: Feb 2020
  */
 public class XMLDTDScannerImpl
 extends XMLScanner
@@ -601,6 +602,7 @@
         if (fScannerState == SCANNER_STATE_END_OF_INPUT)
             return;
 
+        boolean dtdEntity = name.equals("[dtd]");
         // Handle end of PE
         boolean reportEntity = fReportEntity;
         if (name.startsWith("%")) {
@@ -609,8 +611,7 @@
             int startMarkUpDepth = popPEStack();
             // throw fatalError if this entity was incomplete and
             // was a freestanding decl
-            if(startMarkUpDepth == 0 &&
-            startMarkUpDepth < fMarkUpDepth) {
+            if (startMarkUpDepth == 0 && startMarkUpDepth < fMarkUpDepth) {
                 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
                 "ILL_FORMED_PARAMETER_ENTITY_WHEN_USED_IN_DECL",
                 new Object[]{ fEntityManager.fCurrentEntity.name},
@@ -630,12 +631,10 @@
             if (fEntityScanner.isExternal()) {
                 fExtEntityDepth--;
             }
-        }
-
-        // call handler
-        boolean dtdEntity = name.equals("[dtd]");
-        if (fDTDHandler != null && !dtdEntity && reportEntity) {
-            fDTDHandler.endParameterEntity(name, null);
+            // call handler
+            if (fDTDHandler != null && reportEntity) {
+                fDTDHandler.endParameterEntity(name, null);
+            }
         }
 
         // end DTD
--- a/src/com/sun/org/apache/xerces/internal/impl/XMLScanner.java	Wed Apr 15 14:59:36 2020 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/XMLScanner.java	Sat Jul 11 20:36:43 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
  */
 
 /*
@@ -70,6 +70,7 @@
  * @author K.Venugopal SUN Microsystems
  * @author Sunitha Reddy, SUN Microsystems
  * @version $Id: XMLScanner.java,v 1.12 2010-11-01 04:39:41 joehw Exp $
+ * @LastModified: Feb 2020
  */
 public abstract class XMLScanner
         implements XMLComponent {
@@ -1241,10 +1242,10 @@
      * @throws XNIException Thrown by handler to signal an error.
      */
     public void endEntity(String name, Augmentations augs) throws IOException, XNIException {
-
         // keep track of the entity depth
-        fEntityDepth--;
-
+        if (fEntityDepth > 0) {
+            fEntityDepth--;
+        }
     } // endEntity(String)
 
     /**
--- a/src/com/sun/org/apache/xerces/internal/impl/dtd/DTDGrammar.java	Wed Apr 15 14:59:36 2020 +0100
+++ b/src/com/sun/org/apache/xerces/internal/impl/dtd/DTDGrammar.java	Sat Jul 11 20:36:43 2020 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
@@ -61,6 +61,7 @@
  * @author Neil Graham, IBM
  *
  * @version $Id: DTDGrammar.java,v 1.4 2010/08/11 07:18:37 joehw Exp $
+ * @LastModified: Feb 2020
  */
 public class DTDGrammar
     implements XMLDTDHandler, XMLDTDContentModelHandler, EntityState, Grammar {
@@ -445,9 +446,12 @@
      * @throws XNIException Thrown by handler to signal an error.
      */
     public void endParameterEntity(String name, Augmentations augs) throws XNIException {
-
-        fPEDepth--;
-        fReadingExternalDTD = fPEntityStack[fPEDepth];
+        // redundant check as this method can only be called after parsing a PE
+        // incomplete or truncated DTD get caught before reaching this method
+        if (fPEDepth > 0) {
+            fPEDepth--;
+            fReadingExternalDTD = fPEntityStack[fPEDepth];
+        }
 
     } // endParameterEntity(String,Augmentations)