Skip to content

Commit

Permalink
Configure XML parsers used for p2 metadata to eliminate entity limits
Browse files Browse the repository at this point in the history
  • Loading branch information
merks committed Dec 13, 2024
1 parent aa3eef4 commit e526eb4
Showing 1 changed file with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@

public abstract class XMLParser extends DefaultHandler implements XMLConstants {

// Java 24 and onward restricts the number of entities that may appear in an XML
// document. This limit in too restrictive for p2 XML metadata where a large
// update site can easily have 500,000 or more entities.
//
// https://docs.oracle.com/en/java/javase/17/docs/api/java.xml/module-summary.html#IN_ISFPtable
private static final int MAX_ENTITIES = 0;

// Get the root object that is being parsed.
protected abstract Object getRootObject();

Expand Down Expand Up @@ -88,6 +95,18 @@ protected SAXParser getParser() throws ParserConfigurationException, SAXExceptio
if (theParser == null) {
throw new SAXException(Messages.XMLParser_No_SAX_Parser);
}
try {
theParser.setProperty("jdk.xml.totalEntitySizeLimit", //$NON-NLS-1$
Integer.getInteger("jdk.xml.totalEntitySizeLimit", MAX_ENTITIES)); //$NON-NLS-1$
} catch (SAXException se) {
// Maybe not supported.
}
try {
theParser.setProperty("jdk.xml.maxGeneralEntitySizeLimit", //$NON-NLS-1$
Integer.getInteger("jdk.xml.maxGeneralEntitySizeLimit", MAX_ENTITIES)); //$NON-NLS-1$
} catch (SAXException se) {
// Maybe not supported.
}
xmlReader = theParser.getXMLReader();
return theParser;
}
Expand Down

0 comments on commit e526eb4

Please sign in to comment.