diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDTDScannerImpl.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDTDScannerImpl.java index da5ee58fc4be5a6317121059a37b4d03aafdd863..0656a534cebc2481264175cb224d80b5bab2ae9e 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDTDScannerImpl.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDTDScannerImpl.java @@ -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. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -63,7 +63,7 @@ import java.io.IOException; * @author Glenn Marcy, IBM * @author Eric Ye, IBM * - * @LastModified: Nov 2017 + * @LastModified: Feb 2020 */ public class XMLDTDScannerImpl extends XMLScanner @@ -608,6 +608,7 @@ implements XMLDTDScanner, XMLComponent, XMLEntityHandler { if (fScannerState == SCANNER_STATE_END_OF_INPUT) return; + boolean dtdEntity = name.equals("[dtd]"); // Handle end of PE boolean reportEntity = fReportEntity; if (name.startsWith("%")) { @@ -616,8 +617,7 @@ implements XMLDTDScanner, XMLComponent, XMLEntityHandler { 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}, @@ -637,12 +637,10 @@ implements XMLDTDScanner, XMLComponent, XMLEntityHandler { 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 diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java index d9ee34af9df437e1845f27b4fc2974340ec6f58e..6a6362199c52ea826c2540db7580d0b568e9296b 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java @@ -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. */ /* * Licensed to the Apache Software Foundation (ASF) under one or more @@ -67,7 +67,7 @@ import com.sun.xml.internal.stream.Entity; * @author Eric Ye, IBM * @author K.Venugopal SUN Microsystems * @author Sunitha Reddy, SUN Microsystems - * @LastModified: Nov 2017 + * @LastModified: Feb 2020 */ public abstract class XMLScanner implements XMLComponent { @@ -1239,10 +1239,10 @@ public abstract class XMLScanner * @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) /** diff --git a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/dtd/DTDGrammar.java b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/dtd/DTDGrammar.java index 690a5f81e7403b2547748572366850c9e2a84725..d8b4fe3644fb968fad9de1e688276266d64ec71c 100644 --- a/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/dtd/DTDGrammar.java +++ b/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/dtd/DTDGrammar.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, 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 @@ -62,7 +62,7 @@ import java.util.Random; * @author Andy Clark, IBM * @author Neil Graham, IBM * - * @LastModified: Oct 2017 + * @LastModified: Feb 2020 */ public class DTDGrammar implements XMLDTDHandler, XMLDTDContentModelHandler, EntityState, Grammar { @@ -447,9 +447,12 @@ public class DTDGrammar * @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)