fix: report stackLimit exceedance as a parse error, not a thrown exception - #1717
Open
YuEfSaEDU wants to merge 1 commit into
Open
fix: report stackLimit exceedance as a parse error, not a thrown exception#1717YuEfSaEDU wants to merge 1 commit into
YuEfSaEDU wants to merge 1 commit into
Conversation
…ption OurReader::readValue() enforced the configured stackLimit by calling throwRuntimeError() when JSON_USE_EXCEPTION is enabled (the default). The Json::RuntimeError escapes CharReader::parse(), whose contract is to return false and fill in the error string, so a document with ~1100 nested '[' characters terminates an application that does not catch the exception. Report the depth failure through addError() instead, mirroring the existing JSON_USE_EXCEPTION=0 path, and update the CharReaderBuilder documentation accordingly. Fixes open-source-parsers#1704
|
| Filename | Overview |
|---|---|
| include/json/reader.h | Updates the CharReaderBuilder stack-limit documentation to describe parse failure and diagnostic reporting rather than an exception. |
| src/lib_json/json_reader.cpp | Routes OurReader depth-limit violations through addError() so recursive parsing unwinds and returns false without an escaping exception. |
| src/test_lib_json/main.cpp | Updates stack-limit assertions for both exception modes and adds regression coverage for deeply nested arrays and exact diagnostic locations. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart LR
A[CharReader parse input] --> B[OurReader readValue]
B --> C{Depth exceeds stackLimit?}
C -- No --> D[Tokenize and build Value tree]
C -- Yes --> E[Record stack-limit parse error]
E --> F[Unwind nested grammar]
F --> G[Return false with formatted diagnostics]
D --> H[Return parse result]
Reviews (1): Last reviewed commit: "fix: report stackLimit exceedance as a p..." | Re-trigger Greptile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Exceeding the configured
stackLimitmadeCharReader::parse()— the engine behindfromJson-style parsing — terminate the process instead of reporting a parse failure:OurReader::readValue()calledthrowRuntimeError(), and the resultingJson::RuntimeErrorescapesparse()'sbool-return plus error-string contract and goes uncaught in typical callers.This change reports the depth violation through the reader's existing error collection instead, so deeply nested input (for example ~1100 consecutive
[) yieldsfalsewithExceeded stackLimit for nested object and/or array values.at the offending offset, consistent with every other parse error and with the existingJSON_USE_EXCEPTION=0behavior. TheCharReaderBuilderdocumentation forstackLimitis updated to match.CharReaderTest/parseWithStackLimitnow asserts the clean-failure contract for both exception modes, and a newparseDeeplyNestedArrayFailsCleanlytest covers the issue's payload. The full unit suite (133 tests) passes on MSVC x64.Fixes #1704