-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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 support for parse stack limiting #1788
Comments
@xyzzyz I'm also interested in that feature. Any ideas how to implement that? The output routine has the same issue, for that I would just add a |
There are quite some options for Say I have this struct: struct serializer_options
{
bool pretty_print {false};
std::size_t indentation_step {4};
char indentation_char {' '};
bool ensure_ascii {false};
error_handler_t error_handler {error_handler_t::strict};
}; for the current options and their default values and client code with serializer_options options;
options.pretty_print = true;
std::cout << j.dump(options) << std::endl; What would I need to do to avoid breaking this code if I wanted to add std::size stack_limit {0}; to |
Shouldn't it rather be, de-serializer options? This is an issue on parsing side, not on printing side. |
Ooops. Yes. Sorry for the confusion. In any case, the same question also applies for serialization. |
This is not possible. The value of |
Yes, I saw libuv doing this. Then maybe one could use |
Related #1599 |
With the merge of #1436 and thanks to the non-recursive parser, the code will not crash for deeply-nested JSON values anymore. Now the parsing is only bounded by the available memory. Even so, a max-depth parameter for parsing will probably be handy for the user to easily reject a subset of invalid JSONs. |
That's technically true. Though I wonder how users will be affected. For the most part, I think we can manage to add new members to We can also implement One last solution would be to use pimpl trick to keep the struct size constant from the user point of view. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
So we would pass a json document with the options to |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Currently. jsonhpp doesn't support stack limiting for parsing. If you try to parse a string that starts with 100 000 '[' characters, it will most likely overflow stack and crash the whole thread. That makes it unsuitable for parsing untrusted json inputs without separating parser to separate binary, potentially with sandboxing.
Jsonhpp should keep track of the parse stack level, allow for configurable maximum level, and return runtime parsing error whenever stack limit io reached.
The text was updated successfully, but these errors were encountered: