JsonValueWriter can throw StackOverflowError on deeply nested items#44627
JsonValueWriter can throw StackOverflowError on deeply nested items#44627nosan wants to merge 1 commit intospring-projects:3.4.xfrom
Conversation
b3f8244 to
ea08a97
Compare
|
Oh... with |
6849356 to
1777be4
Compare
| */ | ||
| class JsonValueWriter { | ||
|
|
||
| private static final int DEFAULT_MAX_NESTING_DEPTH = 1000; |
There was a problem hiding this comment.
I'm wondering if such a deep nesting level is necessary, as JsonWriter is primarily used for StructuredLogging, and such depth seems practically impossible.
There was a problem hiding this comment.
Maybe this should be configurable? If user decides they want more, they should be able to get more. Default level should be maybe lower, something like 32. Note that this is not only a stack-overflow protection, but also protection against overflowing the storage space for logs.
There was a problem hiding this comment.
I've prototyped some changes main...nosan:44502-json-writer-configuration
This commit adds validation for the maximum JSON nesting depth in the JsonValueWriter. This helps prevent StackOverflowError that can potentially occur due to excessive recursion when dealing with deeply nested JSON structures. Signed-off-by: Dmytro Nosan <dimanosan@gmail.com>
1777be4 to
e36455c
Compare
Add validation for the maximum JSON nesting depth in the JsonValueWriter. This helps prevent a StackOverflowError that can potentially occur due to excessive recursion when dealing with deeply nested JSON structures. See gh-44627 Signed-off-by: Dmytro Nosan <dimanosan@gmail.com>
|
Thanks for the PR @nosan and for the review @thecooldrop! I've gone with a max depth of 500 and I think we should leave it without a configuration option unless we find it causes problems. |
Related to #44502
By default, Jackson uses a nesting depth of 1000.
Jackson:
If you configure Jackson with a nesting depth greater than 1000 (
Integer.MAX_VALUE), a StackOverflowError will also be thrown.Jackson nestingDepth=5000
Gson:
Jsonb: