JSON Deserialization Causes Memory Overflow and Service Restart #4287
Replies: 4 comments 9 replies
-
250Mb isn't very much memory. Newer versions of Jackson have configurable limits - called StreamReadConstraints and these have defaults that should help - but you are advised to tune these constraint values for your own use cases. So try out jackson 2.16.1. Try playing around with lower limits than the defaults. You might also want to write a solution that streams through the JSON instead of binding the whole document. Search around the web for examples but this has a brief write up - https://nurkiewicz.com/2017/09/streaming-large-json-file-with-jackson.html |
Beta Was this translation helpful? Give feedback.
-
I also encountered the same problem, but it is much larger than 250M, as shown in the figure, with 5.7G. How should I limit the modification |
Beta Was this translation helpful? Give feedback.
-
It'd be good to have actual code, class(es) involved. But in general, if you read the contents and bind to a class, there is some memory usage involved. If you want to limit sizes, you will probably need to use combination of input limits that @pjfanning alluded to, as well as design your target object class defitions to limit sizes accepted (like max array or List lengths on setters). |
Beta Was this translation helpful? Give feedback.
-
I ran into a similar problem where I couldn't limit the number of nodes for map objects when deserializing them to map objects. Is there any good solution? Such as: |
Beta Was this translation helpful? Give feedback.
-
Search before asking
Describe the bug
When a JSON character string with many empty nodes is deserialized to a list, (com.fasterxml.jackson.databind.ObjectMapper#readValue(java.lang.String, java.lang.Class)) generates a large number of empty objects, occupying a large amount of memory. Attackers can easily construct attack scenarios and restart services. Does jackson-databind provide a good protection method for this scenario?
Version Information
2.13.5
Reproduction
<-- Any of the following
-->
// Your code here
Expected behavior
No response
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions