-
Notifications
You must be signed in to change notification settings - Fork 41k
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
Add protection against StackOverflowError in JsonValueWriter #44627
base: 3.4.x
Are you sure you want to change the base?
Conversation
b3f8244
to
ea08a97
Compare
Oh... with
|
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 <[email protected]>
6849356
to
1777be4
Compare
@@ -46,8 +46,12 @@ | |||
*/ | |||
class JsonValueWriter { | |||
|
|||
private static final int DEFAULT_MAX_NESTING_DEPTH = 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've prototyped some changes main...nosan:44502-json-writer-configuration
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: