Skip to content

Commit 50cf34d

Browse files
committed
8343004: Adjust JAXP limits
1 parent 21e0fb8 commit 50cf34d

23 files changed

+206
-2658
lines changed

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XML11NSDocumentScannerImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -70,7 +70,7 @@
7070
* @author Michael Glavassevich, IBM
7171
* @author Sunitha Reddy, Sun Microsystems
7272
*
73-
* @LastModified: July 2023
73+
* @LastModified: Nov 2024
7474
*/
7575
public class XML11NSDocumentScannerImpl extends XML11DocumentScannerImpl {
7676

@@ -203,7 +203,8 @@ protected boolean scanStartElement() throws IOException, XNIException {
203203
fAttributes.getLength() > fElementAttributeLimit){
204204
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
205205
"ElementAttributeLimit",
206-
new Object[]{rawname, fElementAttributeLimit },
206+
new Object[]{rawname, fElementAttributeLimit,
207+
XMLSecurityManager.Limit.ELEMENT_ATTRIBUTE_LIMIT.systemProperty() },
207208
XMLErrorReporter.SEVERITY_FATAL_ERROR );
208209
}
209210

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLDocumentFragmentScannerImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
*/
44

55
/*
@@ -74,7 +74,7 @@
7474
* @author Eric Ye, IBM
7575
* @author Sunitha Reddy, SUN Microsystems
7676
*
77-
* @LastModified: Nov 2023
77+
* @LastModified: Nov 2024
7878
*/
7979
public class XMLDocumentFragmentScannerImpl
8080
extends XMLScanner
@@ -1374,7 +1374,8 @@ protected boolean scanStartElement()
13741374
fAttributes.getLength() > fElementAttributeLimit){
13751375
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
13761376
"ElementAttributeLimit",
1377-
new Object[]{rawname, fElementAttributeLimit },
1377+
new Object[]{rawname, fElementAttributeLimit,
1378+
XMLSecurityManager.Limit.ELEMENT_ATTRIBUTE_LIMIT.systemProperty() },
13781379
XMLErrorReporter.SEVERITY_FATAL_ERROR );
13791380
}
13801381

@@ -1885,7 +1886,7 @@ void checkDepth(String elementName) {
18851886
reportFatalError("MaxElementDepthLimit", new Object[]{elementName,
18861887
fLimitAnalyzer.getTotalValue(Limit.MAX_ELEMENT_DEPTH_LIMIT),
18871888
fSecurityManager.getLimit(Limit.MAX_ELEMENT_DEPTH_LIMIT),
1888-
"maxElementDepth"});
1889+
Limit.MAX_ELEMENT_DEPTH_LIMIT.systemProperty()});
18891890
}
18901891
}
18911892

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
* @author K.Venugopal SUN Microsystems
9595
* @author Neeraj Bajaj SUN Microsystems
9696
* @author Sunitha Reddy SUN Microsystems
97-
* @LastModified: Feb 2024
97+
* @LastModified: Nov 2024
9898
*/
9999
public class XMLEntityManager implements XMLComponent, XMLEntityResolver {
100100

@@ -1462,7 +1462,8 @@ public void startEntity(boolean isGE, String name,
14621462
if( fSecurityManager != null && fSecurityManager.isOverLimit(entityExpansionIndex, fLimitAnalyzer)){
14631463
fSecurityManager.debugPrint(fLimitAnalyzer);
14641464
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,"EntityExpansionLimit",
1465-
new Object[]{fSecurityManager.getLimitValueByIndex(entityExpansionIndex)},
1465+
new Object[]{fSecurityManager.getLimitValueByIndex(entityExpansionIndex),
1466+
Limit.ENTITY_EXPANSION_LIMIT.systemProperty()},
14661467
XMLErrorReporter.SEVERITY_FATAL_ERROR );
14671468
// is there anything better to do than reset the counter?
14681469
// at least one can envision debugging applications where this might

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityScanner.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
*/
44

55
/*
@@ -57,7 +57,7 @@
5757
* @author Arnaud Le Hors, IBM
5858
* @author K.Venugopal Sun Microsystems
5959
*
60-
* @LastModified: July 2023
60+
* @LastModified: Nov 2024
6161
*/
6262
public class XMLEntityScanner implements XMLLocator {
6363

@@ -1009,7 +1009,7 @@ protected void checkLimit(Limit limit, ScannedEntity entity, int offset, int len
10091009
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, "TotalEntitySizeLimit",
10101010
new Object[]{fLimitAnalyzer.getTotalValue(Limit.TOTAL_ENTITY_SIZE_LIMIT),
10111011
fSecurityManager.getLimit(Limit.TOTAL_ENTITY_SIZE_LIMIT),
1012-
fSecurityManager.getStateLiteral(Limit.TOTAL_ENTITY_SIZE_LIMIT)},
1012+
Limit.TOTAL_ENTITY_SIZE_LIMIT.systemProperty()},
10131013
XMLErrorReporter.SEVERITY_FATAL_ERROR);
10141014
}
10151015
}

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLNSDocumentScannerImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -54,7 +54,7 @@
5454
* @author Venugopal Rao K, Sun Microsystems
5555
* @author Elena Litani, IBM
5656
*
57-
* @LastModified: July 2023
57+
* @LastModified: Nov 2024
5858
*/
5959
public class XMLNSDocumentScannerImpl
6060
extends XMLDocumentScannerImpl {
@@ -253,7 +253,8 @@ protected boolean scanStartElement()
253253
fAttributes.getLength() > fElementAttributeLimit){
254254
fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN,
255255
"ElementAttributeLimit",
256-
new Object[]{rawname, fElementAttributeLimit },
256+
new Object[]{rawname, fElementAttributeLimit,
257+
XMLSecurityManager.Limit.ELEMENT_ATTRIBUTE_LIMIT.systemProperty() },
257258
XMLErrorReporter.SEVERITY_FATAL_ERROR );
258259
}
259260

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLScanner.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -67,7 +67,7 @@
6767
* @author Eric Ye, IBM
6868
* @author K.Venugopal SUN Microsystems
6969
* @author Sunitha Reddy, SUN Microsystems
70-
* @LastModified: July 2023
70+
* @LastModified: Nov 2024
7171
*/
7272
public abstract class XMLScanner
7373
implements XMLComponent {
@@ -1527,7 +1527,7 @@ void checkEntityLimit(boolean isPEDecl, String entityName, int len) {
15271527
reportFatalError("MaxEntitySizeLimit", new Object[]{"%" + entityName,
15281528
fLimitAnalyzer.getValue(XMLSecurityManager.Limit.PARAMETER_ENTITY_SIZE_LIMIT),
15291529
fSecurityManager.getLimit(XMLSecurityManager.Limit.PARAMETER_ENTITY_SIZE_LIMIT),
1530-
fSecurityManager.getStateLiteral(XMLSecurityManager.Limit.PARAMETER_ENTITY_SIZE_LIMIT)});
1530+
XMLSecurityManager.Limit.PARAMETER_ENTITY_SIZE_LIMIT.systemProperty()});
15311531
}
15321532
} else {
15331533
fLimitAnalyzer.addValue(XMLSecurityManager.Limit.GENERAL_ENTITY_SIZE_LIMIT, entityName, len);
@@ -1536,7 +1536,7 @@ void checkEntityLimit(boolean isPEDecl, String entityName, int len) {
15361536
reportFatalError("MaxEntitySizeLimit", new Object[]{entityName,
15371537
fLimitAnalyzer.getValue(XMLSecurityManager.Limit.GENERAL_ENTITY_SIZE_LIMIT),
15381538
fSecurityManager.getLimit(XMLSecurityManager.Limit.GENERAL_ENTITY_SIZE_LIMIT),
1539-
fSecurityManager.getStateLiteral(XMLSecurityManager.Limit.GENERAL_ENTITY_SIZE_LIMIT)});
1539+
XMLSecurityManager.Limit.GENERAL_ENTITY_SIZE_LIMIT.systemProperty()});
15401540
}
15411541
}
15421542
if (fSecurityManager.isOverLimit(XMLSecurityManager.Limit.TOTAL_ENTITY_SIZE_LIMIT, fLimitAnalyzer)) {

src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/msg/XMLMessages.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@
315315

316316

317317
# Implementation limits
318-
EntityExpansionLimit=JAXP00010001: The parser has encountered more than \"{0}\" entity expansions in this document; this is the limit imposed by the JDK.
319-
ElementAttributeLimit=JAXP00010002: Element \"{0}\" has more than \"{1}\" attributes, \"{1}\" is the limit imposed by the JDK.
318+
EntityExpansionLimit=JAXP00010001: The parser has encountered more than \"{0}\" entity expansions in this document; this is the limit imposed by \"{1}\".
319+
ElementAttributeLimit=JAXP00010002: Element \"{0}\" has more than \"{1}\" attributes, \"{1}\" is the limit set by \"{2}\".
320320
MaxEntitySizeLimit=JAXP00010003: The length of entity \"{0}\" is \"{1}\" that exceeds the \"{2}\" limit set by \"{3}\".
321321
TotalEntitySizeLimit=JAXP00010004: The accumulated size of entities is \"{0}\" that exceeded the \"{1}\" limit set by \"{2}\".
322322
MaxXMLNameLimit=JAXP00010005: The length of entity \"{0}\" is \"{1}\" that exceeds the \"{2}\" limit set by \"{3}\".

src/java.xml/share/classes/jdk/xml/internal/XMLSecurityManager.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -100,23 +100,23 @@ public final class XMLSecurityManager {
100100
@SuppressWarnings("deprecation")
101101
public static enum Limit {
102102
ENTITY_EXPANSION_LIMIT("EntityExpansionLimit", JdkConstants.JDK_ENTITY_EXPANSION_LIMIT,
103-
JdkConstants.SP_ENTITY_EXPANSION_LIMIT, JdkConstants.ENTITY_EXPANSION_LIMIT, 0, 64000, Processor.PARSER, INTMAPPER),
103+
JdkConstants.SP_ENTITY_EXPANSION_LIMIT, JdkConstants.ENTITY_EXPANSION_LIMIT, 2500, 2500, Processor.PARSER, INTMAPPER),
104104
MAX_OCCUR_NODE_LIMIT("MaxOccurLimit", JdkConstants.JDK_MAX_OCCUR_LIMIT,
105-
JdkConstants.SP_MAX_OCCUR_LIMIT, JdkConstants.MAX_OCCUR_LIMIT, 0, 5000, Processor.PARSER, INTMAPPER),
105+
JdkConstants.SP_MAX_OCCUR_LIMIT, JdkConstants.MAX_OCCUR_LIMIT, 5000, 5000, Processor.PARSER, INTMAPPER),
106106
ELEMENT_ATTRIBUTE_LIMIT("ElementAttributeLimit", JdkConstants.JDK_ELEMENT_ATTRIBUTE_LIMIT,
107-
JdkConstants.SP_ELEMENT_ATTRIBUTE_LIMIT, JdkConstants.ELEMENT_ATTRIBUTE_LIMIT, 0, 10000, Processor.PARSER, INTMAPPER),
107+
JdkConstants.SP_ELEMENT_ATTRIBUTE_LIMIT, JdkConstants.ELEMENT_ATTRIBUTE_LIMIT, 200, 200, Processor.PARSER, INTMAPPER),
108108
TOTAL_ENTITY_SIZE_LIMIT("TotalEntitySizeLimit", JdkConstants.JDK_TOTAL_ENTITY_SIZE_LIMIT,
109-
JdkConstants.SP_TOTAL_ENTITY_SIZE_LIMIT, null, 0, 50000000, Processor.PARSER, INTMAPPER),
109+
JdkConstants.SP_TOTAL_ENTITY_SIZE_LIMIT, null, 100000, 100000, Processor.PARSER, INTMAPPER),
110110
GENERAL_ENTITY_SIZE_LIMIT("MaxEntitySizeLimit", JdkConstants.JDK_GENERAL_ENTITY_SIZE_LIMIT,
111-
JdkConstants.SP_GENERAL_ENTITY_SIZE_LIMIT, null, 0, 0, Processor.PARSER, INTMAPPER),
112-
PARAMETER_ENTITY_SIZE_LIMIT("MaxEntitySizeLimit", JdkConstants.JDK_PARAMETER_ENTITY_SIZE_LIMIT,
113-
JdkConstants.SP_PARAMETER_ENTITY_SIZE_LIMIT, null, 0, 1000000, Processor.PARSER, INTMAPPER),
111+
JdkConstants.SP_GENERAL_ENTITY_SIZE_LIMIT, null, 100000, 100000, Processor.PARSER, INTMAPPER),
112+
PARAMETER_ENTITY_SIZE_LIMIT("MaxParameterEntitySizeLimit", JdkConstants.JDK_PARAMETER_ENTITY_SIZE_LIMIT,
113+
JdkConstants.SP_PARAMETER_ENTITY_SIZE_LIMIT, null, 15000, 15000, Processor.PARSER, INTMAPPER),
114114
MAX_ELEMENT_DEPTH_LIMIT("MaxElementDepthLimit", JdkConstants.JDK_MAX_ELEMENT_DEPTH,
115-
JdkConstants.SP_MAX_ELEMENT_DEPTH, null, 0, 0, Processor.PARSER, INTMAPPER),
115+
JdkConstants.SP_MAX_ELEMENT_DEPTH, null, 100, 100, Processor.PARSER, INTMAPPER),
116116
MAX_NAME_LIMIT("MaxXMLNameLimit", JdkConstants.JDK_XML_NAME_LIMIT,
117117
JdkConstants.SP_XML_NAME_LIMIT, null, 1000, 1000, Processor.PARSER, INTMAPPER),
118118
ENTITY_REPLACEMENT_LIMIT("EntityReplacementLimit", JdkConstants.JDK_ENTITY_REPLACEMENT_LIMIT,
119-
JdkConstants.SP_ENTITY_REPLACEMENT_LIMIT, null, 0, 3000000, Processor.PARSER, INTMAPPER),
119+
JdkConstants.SP_ENTITY_REPLACEMENT_LIMIT, null, 100000, 100000, Processor.PARSER, INTMAPPER),
120120
XPATH_GROUP_LIMIT("XPathGroupLimit", JdkConstants.XPATH_GROUP_LIMIT,
121121
JdkConstants.XPATH_GROUP_LIMIT, null, 10, 10, Processor.XPATH, INTMAPPER),
122122
XPATH_OP_LIMIT("XPathExprOpLimit", JdkConstants.XPATH_OP_LIMIT,

src/java.xml/share/classes/module-info.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -602,8 +602,8 @@
602602
* A positive integer. A value less than or equal to 0 indicates no limit.
603603
* If the value is not an integer, a NumberFormatException is thrown.
604604
* </td>
605-
* <td style="text-align:center">64000</td>
606-
* <td style="text-align:center">64000</td>
605+
* <td style="text-align:center">2500</td>
606+
* <td style="text-align:center">2500</td>
607607
* <td style="text-align:center" rowspan="9">Yes</td>
608608
* <td style="text-align:center" rowspan="9">
609609
* <a href="#DOM">DOM</a><br>
@@ -619,8 +619,8 @@
619619
* <td id="EALimit">{@systemProperty jdk.xml.elementAttributeLimit}</td>
620620
* <td>Limits the number of attributes an element can have.
621621
* </td>
622-
* <td style="text-align:center">10000</td>
623-
* <td style="text-align:center">10000</td>
622+
* <td style="text-align:center">200</td>
623+
* <td style="text-align:center">200</td>
624624
* </tr>
625625
* <tr>
626626
* <td id="OccurLimit">{@systemProperty jdk.xml.maxOccurLimit}</td>
@@ -636,37 +636,37 @@
636636
* <td>Limits the total size of all entities that include general and parameter
637637
* entities. The size is calculated as an aggregation of all entities.
638638
* </td>
639-
* <td style="text-align:center">5x10^7</td>
640-
* <td style="text-align:center">5x10^7</td>
639+
* <td style="text-align:center">100000</td>
640+
* <td style="text-align:center">100000</td>
641641
* </tr>
642642
* <tr>
643643
* <td id="GELimit">{@systemProperty jdk.xml.maxGeneralEntitySizeLimit}</td>
644644
* <td>Limits the maximum size of any general entities.
645645
* </td>
646-
* <td style="text-align:center">0</td>
647-
* <td style="text-align:center">0</td>
646+
* <td style="text-align:center">100000</td>
647+
* <td style="text-align:center">100000</td>
648648
* </tr>
649649
* <tr>
650650
* <td id="PELimit">{@systemProperty jdk.xml.maxParameterEntitySizeLimit}</td>
651651
* <td>Limits the maximum size of any parameter entities, including the result
652652
* of nesting multiple parameter entities.
653653
* </td>
654-
* <td style="text-align:center">10^6</td>
655-
* <td style="text-align:center">10^6</td>
654+
* <td style="text-align:center">15000</td>
655+
* <td style="text-align:center">15000</td>
656656
* </tr>
657657
* <tr>
658658
* <td id="ERLimit">{@systemProperty jdk.xml.entityReplacementLimit}</td>
659659
* <td>Limits the total number of nodes in all entity references.
660660
* </td>
661-
* <td style="text-align:center">3x10^6</td>
662-
* <td style="text-align:center">3x10^6</td>
661+
* <td style="text-align:center">100000</td>
662+
* <td style="text-align:center">100000</td>
663663
* </tr>
664664
* <tr>
665665
* <td id="ElementDepth">{@systemProperty jdk.xml.maxElementDepth}</td>
666666
* <td>Limits the maximum element depth.
667667
* </td>
668-
* <td style="text-align:center">0</td>
669-
* <td style="text-align:center">0</td>
668+
* <td style="text-align:center">100</td>
669+
* <td style="text-align:center">100</td>
670670
* </tr>
671671
* <tr>
672672
* <td id="NameLimit">{@systemProperty jdk.xml.maxXMLNameLimit}</td>

src/java.xml/share/conf/jaxp-strict.properties.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ jdk.xml.maxParameterEntitySizeLimit=15000
9696
jdk.xml.entityReplacementLimit=100000
9797
#
9898
# Limits the number of attributes an element can have. The default value is 10000.
99-
jdk.xml.elementAttributeLimit=10000
99+
jdk.xml.elementAttributeLimit=200
100100
#
101101
# Limits the number of content model nodes that may be created when building a
102102
# grammar for a W3C XML Schema that contains maxOccurs attributes with values
103103
# other than "unbounded". The default value is 5000.
104104
jdk.xml.maxOccurLimit=5000
105105
#
106106
# Limits the maximum element depth. The default value is 0.
107-
jdk.xml.maxElementDepth=0
107+
jdk.xml.maxElementDepth=100
108108
#
109109
# Limits the maximum size of XML names, including element name, attribute name
110110
# and namespace prefix and URI. The default value is 1000.

0 commit comments

Comments
 (0)