-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize JsonNodeDeserialization
wrt recursion
#3397
Comments
Note: implementation was merged from branch |
Same issue occurs when using e.g. Looks like the recursion in I assume this is related to this issue or should I open a new bug issue for that? Will the provided fix cover that part as well? |
@denizhusaj #3416 (which fixed the CVE #2816) specifically fixed the StackOverflowError that can be caused by deeply nested JSON. This is not an issue for JsonNode anymore because in 2.13.0 the JsonNode impl was changed to be iterative. However even the iterative implementation can still take a while if you feed it 50m arrays. It is simply a lot of tokens :) |
@yawkat So there are no plans to forbid deeply nested JSON Arrays? But somehow I still get a |
@denizhusaj i cannot reproduce that issue. I tried a nested JsonNode object with 50000 levels like in your example. It parsed just fine. Maybe your error comes from JsonNode.toString? That will still error, however that is more of a debugging method. |
@yawkat yes sorry you are right, it comes from the toString()... Method threw 'java.lang.StackOverflowError' exception. Cannot evaluate com.fasterxml.jackson.databind.node.ObjectNode.toString() But regarding deep nested JSONArrays there will be no depth limit? |
I can't say that, it's tatu's decision. However I'm not convinced a depth limit would help with "long texts take a long time to parse" completely. In general you can also allocate a lot of objects without very deep json, e.g. There is one problem that is unique to deeply nested json in particular (as opposed to other ways of getting many tokens): This line limits the expansion of the |
@denizhusaj Could you file a separate issue for As to plans: yes, there is a plan but it'd be via lower level streaming API: since handling it for all distinct deserializers is more work, configurability, so this aspect (maximum input document size/complexity limits) seems better addresses with more general functionality. |
@cowtowncoder yes sure #3447 |
(note: cleaved off of #2816, used to be bundled)
Current implementation
JsonNodeDeserialization
is expensive for deeply nested Object and Array values as it uses recursion: so for each small additional nesting level -- for arrays, 2 bytes to encode[
and]
-- a new stack frame gets created.In practical terms this means that it is possible to exhaust JVM heap usage with document that has nesting in order of ten thousand(s) levels, depending on settings.
It should be possible to replace basic recursion, however, with iteration, to at least significantly reduce amplification: to prevent cheapest potential DoS concerns.
The text was updated successfully, but these errors were encountered: