Skip to content

Limits ​

The limits the readers enforce on a document, with their defaults and the error code each raises. They bound the memory and time a document can consume, however small its input. Untrusted input describes the attacks they guard against.

Reader limits ​

An entity is named replacement text declared in a DTD. The reader substitutes it for each reference to it, such as &name;, and each substitution is one expansion.

LimitDefaultWhat it countsError when exceeded
entityExpansions2,500Entity expansions in one documentLIMIT_ENTITY_EXPANSIONS
totalEntitySize100,000Total characters produced by all entity expansions in one documentLIMIT_TOTAL_ENTITY_SIZE
generalEntitySize100,000Characters in one general entity, referenced from content or an attribute valueLIMIT_GENERAL_ENTITY_SIZE
parameterEntitySize15,000Characters in one parameter entity, referenced from within the DTDLIMIT_PARAMETER_ENTITY_SIZE
entityReferenceNodes100,000Events produced inside entity replacement textLIMIT_ENTITY_REPLACEMENT
attributesPerElement200Attributes on one elementLIMIT_ATTRIBUTES
elementDepth100Nesting depth of elementsLIMIT_ELEMENT_DEPTH
nameLength1,000Characters in one nameLIMIT_NAME_LENGTH

Exceeding a limit throws an XMLError with the code shown and ends the document. Document size and the length of character data are not limited.

Change a limit ​

Set limits on the factory. Omitted limits keep their defaults, which are also exported as DEFAULT_LIMITS.

ts
import { 
DEFAULT_LIMITS
,
XMLInputFactory
} from '@exemplarjs/xml';
const
factory
= new
XMLInputFactory
({
limits
: {
elementDepth
: 500,
entityExpansions
: 10_000 },
});
console
.
log
(
DEFAULT_LIMITS
.
elementDepth
); // 100
console
.
log
(
factory
.
options
.
limits
.
elementDepth
); // 500
console
.
log
(
factory
.
options
.
limits
.
nameLength
); // 1000

Coming from Java

The defaults are those of JDK 24. Coming from Java maps each limit to its jdk.xml property.

Fixed limits in XPath ​

These limits are fixed and not configurable.

What is limitedLimitError when exceeded
Integers materialized by a range expression such as 1 to 2000000010 millionXPDY0130
Nesting of objects and arrays read by parse-json, json-doc and json-to-xml1,000 deepFOJS0001
Arity of a function item1,048,576FOAR0002

A comparison against a range, such as $x = (1 to 100000000), does not materialize the integers and is not limited.

Released under the Apache License 2.0.