-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
JSONObject/Array should be protected from stack overflow exceptions caused by recursion #722
Comments
Hey, @stleary . What if we use a programmatic stack data structure (ArrayDeque, for example) with iteration to do the parsing instead of recursion? |
JSONObject and JSONArray both use JSONTokener class, where the nextValue function catches and handles the StackOverflowError. This leaves JSONML to be fixed - PR in progress. |
@cleydyr I think the risk of missing something in a complete rewrite of the parser would outweigh the benefit of fixing the stack overflow. |
I don’t think catching StackOverflowError’s can be reliably counted on as being safe? |
See JDK-8067946. |
Fair enough - although it works OK in my environment, throwing StackOverflowError as expected, other platforms may behave in a different way. Now that I have the unit tests, only the implementation is left to do. |
Dunno if it would be worth noting that this means the original fix for CVE-2022-45690 could be considered incomplete, since the JVM could still crash in some circumstances? |
FYI, another StackOverflowError, based upon dromara/hutool#2749:
|
I also think
|
|
I didn't do a complete rewrite of the parser. I made some refactorings in the beginning and rearranged the parsing code to emulate recursive calls with ArrayDeque of ParsingContext (which is a class for holding local variables and the point in the parsing process where the parser is). (The schema in https://www.json.org/json-en.html helped a lot.) I covered both JSONML and JSONArray/JSONObject with my fix. It's passing all tests (though, of course, I removed the tests that counted on the code StackOverflow being thrown). I'll send you a PR so that you have a look at it. |
JSONML should be protected from stack overflow exceptions caused by recursion, resolving #722
See #720 for an example of this might be done.
The text was updated successfully, but these errors were encountered: