-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Confusion between \0
and EOF can lead to OutOfMemoryError
#758
Comments
Do you have an actual test to validate this? I'd argue that valid text input should never have a |
Yes, I have a test that can provoke OutOfMemoryError with a small input, though I'm not going to publish it until a fix has been released. Yes, |
Without a PoC, I doubt anyone else will fix this. Feel free to submit a PR. I don't think I'd consider a OOME a security issue, but if you feel different, follow the instructions for those here: |
I think Denial of Service attacks kind of are security issues, aren't they? If you can make a server fall over by firing carefully-crafted JSON at it, that seems not great. Anyway, yes, my next step was to submit a PR. (I have already shared repro details with @stleary.) |
A better solution might be to use -1 instead 0 to represent EOF everywhere, which of course means changing `char` variables to `int`. The solution here is enough to solve the immediate problem, though. Fixes stleary#758.
@eamonnmcmanus Good catch and thanks for bringing this up. In this case, it's OK to post the recreate code and proposed fix. |
DoS issues are about reliability. They are not security issues in and of themselves. If the DoS leads to some other other issues like memory corruption or getting access to information that shouldn't be available, then it would track as security. |
See: stleary/JSON-java#758 stleary/JSON-java#759 Port pull #759 from stleary/JSON-java to help address OOM errors described in https://www.cve.org/CVERecord?id=CVE-2023-5072 To support the JSONTokener.end() function this relies on, port over the 'eof' flag & set in all locations it's used in the latest JSON-java. Use the String next(int n) implementation from more recent java versions so we can properly check end() while reading a group of characters. Test by: - importing into alpha locally & running all tests that depend on //thirdparty:json - verifying that Snyk's proof-of-concept does not cause OOMs: https://security.snyk.io/vuln/SNYK-JAVA-ORGJSON-5962464
JSONTokener.next()
uses a 0 return to indicate EOF. But 0 is also returned when an actual\0
character is read. In some circumstances that can be used to circumvent parser checks. Parsing untrusted input could then potentially lead to OutOfMemoryError even for quite small input strings.The text was updated successfully, but these errors were encountered: