Skip to content
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

JSON parsing should detect embedded \0 values #759

Merged
merged 3 commits into from
Aug 5, 2023

Conversation

eamonnmcmanus
Copy link
Contributor

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 #758.

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.
@stleary
Copy link
Owner

stleary commented Aug 2, 2023

What problem does this code solve?
JSONObject Tokenizer does not handle chars with value '\0' correctly, since this value is internally used to signal the end of text. JSONArray does not have this problem because this returned value results in a syntax exception.

Risks
Low

Changes to the API?
No

Will this require a new release?
No

Should the documentation be updated?
No

Does it break the unit tests?
No. A new unit test was added.

Was any code refactored in this commit?
No

Review status
APPROVED

Starting 3-day comment window.

@stleary stleary changed the title Don't skip past \0 when parsing JSON objects. JSON parsing should detect embedded \0 values Aug 2, 2023
@eamonnmcmanus
Copy link
Contributor Author

Will this require a new release?
No

There probably is going to be a CVE for the DoS issue, so you might want to plan for a release that includes the fix.

@stleary stleary merged commit 60662e2 into stleary:master Aug 5, 2023
5 checks passed
@stleary
Copy link
Owner

stleary commented Aug 5, 2023

No worries, a new version can be released if/when the CVE is added

@eamonnmcmanus eamonnmcmanus deleted the eofnull branch August 23, 2023 18:27
johnjaylward pushed a commit to johnjaylward/JSON-java that referenced this pull request Oct 17, 2023
JSON parsing should detect embedded `\0` values
claireagordon added a commit to yext/JSON-java that referenced this pull request Mar 26, 2024
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
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Confusion between \0 and EOF can lead to OutOfMemoryError
3 participants