Repository navigation
(ion) Enforce maxNestingDepth when reading IonValue - #911
Open
Dhanu-dynamic wants to merge 1 commit into
Open
Dhanu-dynamic wants to merge 1 commit into
Dhanu-dynamic wants to merge 1 commit into
Conversation
IonParser.getIonValue() copied the value with IonWriter.writeValue(IonReader), which copies the whole subtree without going through nextToken(), so the depth check from FasterXML#803 did not apply to IonValue binding. Copy containers one level at a time and validate depth on each step in (see FasterXML#358).
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
IonParser.getIonValue(), whichgetEmbeddedObject()falls through to andIonValueDeserializercalls on the first token, copied the value withIonWriter.writeValue(IonReader). ion-java copies the whole subtree in that one call, sonextToken()and thevalidateNestingDepth()check from #803 never run, andreadValue(..., IonValue.class)or anyIonValue-typed property ignoresmaxNestingDepth. WithmaxNestingDepth(10)a 20-deep list reads fine; with the default (1000) a 200,000-deep list (400 KB of text) is accepted. This is the caveat noted in the #358 status comment._copyValue()now walks containers one level at a time and validates depth on each step in, counting from the parser context so a property value is measured from the document root, the same asnextToken(). Scalars and null containers still go throughwriteValue(). The walk is iterative, so with the limit raised toInteger.MAX_VALUEthe 200,000-deep document still reads without aStackOverflowError. Field names and annotations are kept; the at-limit test compares the result againstIonSystem.singleValue().Tests are in
DeeplyNestedIonReadTest; the two over-limit ones fail without theIonParserchange.mvn verifyinion: 290 tests, 0 failures. Based on2.21;3.1has the samewriteValue(_reader)call, so it should merge forward cleanly. I left out the release-notes entry since there is no PR number yet, and can add it.