enforce maxStringLength/maxNameLength read constraints in XML parser - #917
Sahana2524 wants to merge 1 commit into
Conversation
|
This only occurs after-the-fact, XML parser having decoded element/attribute name, text value. |
|
Agreed, this is a post-decode check: by the time getText() or the name decode runs, the Stax reader has already buffered the whole value, so it doesn't bound memory inside the XML parser the way Woodstox's P_MAX_TEXT_LENGTH / P_MAX_ATTRIBUTE_SIZE do. What it does buy is that a configured StreamReadConstraints isn't quietly ignored on the XML side, it applies whichever Stax implementation is underneath (along the lines of your note on #891 about not leaning on Woodstox's depth limit alone), and the value is rejected during nextToken() with the same StreamConstraintsException the JSON backend throws, before databind consumes it. If you'd rather not carry it, or want the javadoc to say explicitly that the Woodstox properties are the parser-level guard, I can adjust either way. |
maxStringLength/maxNameLengthare ignored when reading XMLThe read path never runs the configured
StreamReadConstraintsover element text, attribute values, or element/attribute/root names, so those two limits have no effect on deserialization even though the write side and the JSON backend honor them. WithmaxStringLength(100)a 5000-char text value or attribute value parses cleanly, and withmaxNameLength(50)a 5000-char element, attribute, or root name parses cleanly.This complements the
maxNestingDepthwork in #891 by covering the content-length limits. The checks live whereXmlTokenStreammaterializes each value:validateStringLengthat the single text accessor (getText(), which every element-text and attribute value passes through) andvalidateNameLengthat the two name-decode points (_decodeElementName/_decodeAttributeName, which every name passes through). The constraints are threaded in fromIOContext. Default limits are unchanged, so normal documents behave exactly as before;maxDocumentLength(#609) is a separate concern and not addressed here.