refactor(http): improve JsonFormat parser robustness#6845
Merged
lvs0075 merged 1 commit intoJun 17, 2026
Merged
Conversation
Improve the hand-rolled JsonFormat parser used by HTTP wallet APIs so field-heavy and deeply nested JSON no longer overflows the request thread stack. mergeField now consumes one field per call and leaves comma iteration to the caller. JsonFormat also enforces Constant.MAX_NESTING_DEPTH for object/array descent and returns ParseException instead of allowing StackOverflowError to escape. Compatibility notes: direct JsonFormat.merge callers now reject nesting beyond 100 levels; trailing commas on known-field parse paths (top-level fields, known message fields, and known repeated fields) may be accepted, while trailing commas inside unknown nested object/array fields remain rejected; malicious deep-nesting requests now surface as parse errors instead of container-level HTTP 500s.
529bb2f to
554898b
Compare
bladehan1
reviewed
Jun 16, 2026
bladehan1
approved these changes
Jun 16, 2026
Sunny6889
approved these changes
Jun 17, 2026
waynercheung
approved these changes
Jun 17, 2026
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.
What does this PR do?
Improves
JsonFormatparsing robustness for protobuf JSON used by HTTP wallet APIs.JsonFormat.Why are these changes required?
The previous parser could consume an excessive call stack when processing very field-heavy or deeply nested JSON input. This PR makes the parser fail predictably with
ParseExceptionfor overly deep input, while keeping normal JSON/protobuf parsing behavior compatible.This PR has been tested by:
./gradlew :framework:test --tests org.tron.core.services.http.JsonFormatTest --tests org.tron.core.services.http.TriggerConstantContractServletTest :framework:checkstyleTest -x generateGitProperties./gradlew lintConstant.MAX_NESTING_DEPTHremains accepted.Follow up
None required.
Extra details
Compatibility notes:
Direct
JsonFormat.merge()callers now reject protobuf JSON nesting beyondConstant.MAX_NESTING_DEPTHwithParseException: Hit recursion limit..HTTP API compatibility risk is low because the normal HTTP JSON path already applies Jackson's
MAX_NESTING_DEPTH = 100.Deeply nested invalid input now returns a parser error instead of surfacing as a container-level HTTP 500.
invalid abi. Other ABI inputs that failJsonFormatparsing may now also be reported as invalid params instead of internal error; this only affects invalid ABI input.Compatibility notes for trailing commas:
{"address":"61646472657373",}ParseException{"genesisBlockId":{"hash":"00","number":1,}}ParseException{"approvals":["00","01",]}{"zzz":{"a":1,}}ParseExceptionParseException{"zzz":[1,]}ParseExceptionParseException{"address":"61646472657373",,}ParseExceptionParseExceptionThis is an input-acceptance relaxation for top-level fields and known nested protobuf message fields. It is aligned with the existing
org.tron.json.JSONbehavior, which already allows a single trailing comma while rejecting repeated commas.