Skip to content

Commit ce66b07

Browse files
committed
Updated limits and added thread safety to catalog
1 parent a45475c commit ce66b07

4 files changed

Lines changed: 14 additions & 6 deletions

File tree

lib/xmljava.jar

286 Bytes
Binary file not shown.

src/com/maxprograms/xml/Catalog.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class Catalog implements EntityResolver2 {
5757
private Map<String, Catalog> delegateCatalogs;
5858
private String workDir;
5959
private String base = "";
60-
private String documentParent = "";
60+
private final ThreadLocal<String> documentParent = ThreadLocal.withInitial(() -> "");
6161
private String prefer = "public";
6262

6363
protected Catalog(String catalogFile)
@@ -554,7 +554,7 @@ public String matchSystem(String baseURI, String systemId) {
554554
}
555555
// this resource is not in catalog.
556556

557-
if (!documentParent.isEmpty()) {
557+
if (!documentParent.get().isEmpty()) {
558558
// try to find the file in parent folder
559559
File f = new File(systemId);
560560
String name = f.getAbsolutePath();
@@ -566,14 +566,14 @@ public String matchSystem(String baseURI, String systemId) {
566566
name = f.getName();
567567
}
568568
}
569-
File parent = new File(documentParent);
569+
File parent = new File(documentParent.get());
570570
File file = new File(parent, name);
571571
if (file.exists()) {
572572
return file.getAbsolutePath();
573573
}
574574
}
575575
try {
576-
URI u = new URI(baseURI != null ? baseURI : documentParent).resolve(systemId).normalize();
576+
URI u = new URI(baseURI != null ? baseURI : documentParent.get()).resolve(systemId).normalize();
577577
File file = new File(u.toURL().toString());
578578
if (file.exists()) {
579579
return file.getAbsolutePath();
@@ -636,7 +636,7 @@ public String matchURI(String uri) {
636636
}
637637

638638
public void currentDocumentBase(String parentFile) {
639-
documentParent = parentFile;
639+
documentParent.set(parentFile);
640640
}
641641

642642
public String getDTD(String name) {

src/com/maxprograms/xml/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
public class Constants {
1414

1515
public static final String VERSION = "5.0.0";
16-
public static final String BUILD = "20260609_1150";
16+
public static final String BUILD = "20260610_0723";
1717

1818
private Constants() {
1919
// private for security

src/com/maxprograms/xml/SAXBuilder.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ public Document build(ByteArrayInputStream stream) throws SAXException, IOExcept
7979
parser.setFeature("http://apache.org/xml/features/validation/dynamic", true);
8080
}
8181
parser.setProperty("http://www.oracle.com/xml/jaxp/properties/totalEntitySizeLimit", 0);
82+
parser.setProperty("http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit", 0);
83+
parser.setProperty("http://www.oracle.com/xml/jaxp/properties/maxParameterEntitySizeLimit", 0);
84+
parser.setProperty("http://www.oracle.com/xml/jaxp/properties/maxGeneralEntitySizeLimit", 0);
85+
parser.setProperty("http://www.oracle.com/xml/jaxp/properties/maxXMLNameLimit", 0);
8286
boolean clearHandler = false;
8387
if (contentHandler == null) {
8488
contentHandler = new CustomContentHandler();
@@ -145,6 +149,10 @@ public Document build(URL url) throws SAXException, IOException, ParserConfigura
145149
parser.setFeature("http://apache.org/xml/features/validation/dynamic", true);
146150
}
147151
parser.setProperty("http://www.oracle.com/xml/jaxp/properties/totalEntitySizeLimit", 0);
152+
parser.setProperty("http://www.oracle.com/xml/jaxp/properties/entityExpansionLimit", 0);
153+
parser.setProperty("http://www.oracle.com/xml/jaxp/properties/maxParameterEntitySizeLimit", 0);
154+
parser.setProperty("http://www.oracle.com/xml/jaxp/properties/maxGeneralEntitySizeLimit", 0);
155+
parser.setProperty("http://www.oracle.com/xml/jaxp/properties/maxXMLNameLimit", 0);
148156
boolean clearHandler = false;
149157
if (contentHandler == null) {
150158
contentHandler = new CustomContentHandler();

0 commit comments

Comments
 (0)