Repository navigation
Enforce maxNestingDepth when reading IonValue - #911
Open
Dhanu-dynamic wants to merge 8 commits into
Open
Dhanu-dynamic wants to merge 8 commits into
Dhanu-dynamic wants to merge 8 commits 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).
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Validate nesting depth before stepping into a container and step reader back out on constraint violation, so `nextToken()` continues from the following value. Report `IonException` from the copy loop via `_reportCorruptContent()` as elsewhere. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Cover binary structs, s-expressions, annotated containers and a reader already positioned inside a container; comments now cite FasterXML#911. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Any failure during copy now marks reader to be stepped back out by `nextToken()`, instead of eagerly and only for constraint violations; non-`IonException` runtime failures are reported as corrupt content. `getEmbeddedObject()` without current value fails with parse exception instead of `IndexOutOfBoundsException`. Release note no longer refers to private method. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Removes pending step-out state: reader is stepped out as soon as copy fails. Also avoid NPE from `getEmbeddedObject()` / `getBinaryValue()` when reader has no current value, and only convert exception types `ion-java` throws for invalid content. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
maxNestingDepth when reading IonValuemaxNestingDepth when reading IonValue
Member
|
Been changing this pr with Claude Code, but seems to go in circles; will try to stabilize. |
Stepping reader out of the rejected value requires reading the rest of it, so nesting depth violation would not fail fast. Parser is not usable after failed copy. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.