Add sensible defaults to StaxUtils's MAX_ELEMENT_COUNT and MAX_XML_CHARACTERS - #3463
Conversation
|
@reta Some comments from Claude: 1.
|
maxChildElements |
resulting MAX_ELEMENT_COUNT_VAL |
|---|---|
| 50 000 (default) | 5 000 000 |
| 30 000 000 | 50 000 |
Integer.MAX_VALUE |
50 000 (100 * Integer.MAX_VALUE wraps to -100, so the floor wins) |
That inverts the invariant the comment states — the total element count ends up well below the per-parent child count. It also hits precisely the users most likely to notice: getInteger/getLong coerce negatives back to the default, so there is no -1 escape hatch and raising maxChildElements is the only way to relax that limit today. Anyone doing so would silently pick up a 50 000 total-element cap on upgrade.
One character:
getLong(MAX_ELEMENT_COUNT, Math.max(100L * MAX_CHILD_ELEMENTS_VAL, 50000L));2. Derive maxXMLCharacters from MAX_TEXT_LENGTH_VAL
Your rationale above is "2x of MAX_TEXT_LENGTH" and the new code comment says the two "should be aligned", but the code hardcodes 256Mb — so the alignment breaks as soon as anyone sets org.apache.cxf.stax.maxTextLength. Raise it to 512Mb and the document-wide character cap is smaller than a single permitted text segment: a contradictory config that worked fine before this change.
private static final long MAX_XML_CHARS_VAL =
getLong(MAX_XML_CHARACTERS, 2L * MAX_TEXT_LENGTH_VAL); // 256Mb by defaultSame default (2 x 128Mb), stays correct under reconfiguration, and makes the comment true rather than aspirational. If you'd rather keep the literal, at least 256L * 1024 * 1024 so a future bump doesn't overflow.
|
Thanks @coheigea
I will widen it to long, thanks!
The straight derivation does not make sense here to be fair. MAX_TEXT_LENGTH_VAL is really large by default, but we should not use multipliers there (ideally, I would think of MAX_TEXT_LENGTH_VAL as 8k and MAX_XML_CHARACTERS as 32Mb fe), so 256Mb is just reasonably large value that is not in conflict with MAX_TEXT_LENGTH_VAL default. |
Add sensible defaults to StaxUtils's MAX_ELEMENT_COUNT and MAX_XML_CHARACTERS