Skip to content

Conversation

neumannt
Copy link
Contributor

Passing a deeply nested JSON structure to json::load leads to a crash
due to stack overflow. We handle this now gracefully by limiting the
maximum nesting depth to 10,000.

Test case:

https://github.com/nst/JSONTestSuite/blob/master/test_parsing/n_structure_100000_opening_arrays.json

Passing a deeply nested JSON structure to json::load leads to a crash
due to stack overflow. We handle this now gracefully by limiting the
maximum nesting depth to 10,000.

Test case:

https://github.com/nst/JSONTestSuite/blob/master/test_parsing/n_structure_100000_opening_arrays.json
Copy link
Member

@The-EDev The-EDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything seems to be in order, but I would still appreciate a 2nd review just to be absolutely sure that nothing else would be affected.

On a separate note, it might be worth testing Crow against the linked JSON tests, or possibly incorporating them into Crow's own tests.

@neumannt
Copy link
Contributor Author

I have run the whole test suite, of course. The parser does mostly fine, it accepts some cases that it should not and it rejects a few corner cases that will most likely never happen in practice. I was mostly interested in potential crashes, as these are really dangerous with untrusted input.

With this commit all test files can be read without crashing. I plan to use a fuzzer to check for further potential crash issues.

Copy link
Collaborator

@luca-schlecker luca-schlecker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. 👍

@The-EDev The-EDev merged commit 9f64a7b into CrowCpp:master Jan 29, 2022
@neumannt neumannt deleted the json-crash branch January 29, 2022 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants