Skip to content

(ion) Enforce maxNestingDepth when reading IonValue - #911

Open
Dhanu-dynamic wants to merge 1 commit into
FasterXML:2.21from
Dhanu-dynamic:2.21/ion-ionvalue-nesting-depth
Open

Dhanu-dynamic wants to merge 1 commit into
FasterXML:2.21from
Dhanu-dynamic:2.21/ion-ionvalue-nesting-depth

Conversation

@Dhanu-dynamic

Copy link
Copy Markdown
Contributor

IonParser.getIonValue(), which getEmbeddedObject() falls through to and IonValueDeserializer calls on the first token, copied the value with IonWriter.writeValue(IonReader). ion-java copies the whole subtree in that one call, so nextToken() and the validateNestingDepth() check from #803 never run, and readValue(..., IonValue.class) or any IonValue-typed property ignores maxNestingDepth. With maxNestingDepth(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 as nextToken(). Scalars and null containers still go through writeValue(). The walk is iterative, so with the limit raised to Integer.MAX_VALUE the 200,000-deep document still reads without a StackOverflowError. Field names and annotations are kept; the at-limit test compares the result against IonSystem.singleValue().

Tests are in DeeplyNestedIonReadTest; the two over-limit ones fail without the IonParser change. mvn verify in ion: 290 tests, 0 failures. Based on 2.21; 3.1 has the same writeValue(_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.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant