fix: harden ABI parser bounds and revert reason decoding#12
fix: harden ABI parser bounds and revert reason decoding#120xbigapple wants to merge 2 commits intodevelopfrom
Conversation
📝 WalkthroughWalkthroughThis PR enhances error handling and safety in contract event parsing and JSON-RPC execution. Changes include UTF-8 charset enforcement for string decoding, strengthened length validation with explicit exception throwing, refined byte-slicing bounds checking, revert reason extraction with payload size limits, and comprehensive test coverage for both features. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR hardens ABI decoding against malformed dynamic offsets/lengths in the contract event parser and makes JSON-RPC revert reason handling safer and shared between eth_call and eth_estimateGas.
Changes:
- Tighten
ContractEventParser.subBytes()bounds checks and reject negative dynamic lengths during ABI decoding. - Extract revert reason decoding into
TronJsonRpcImpl.tryDecodeRevertReason()and reuse it ineth_call/eth_estimateGas. - Add unit tests covering malformed ABI payloads for both event parsing and revert reason decoding.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| framework/src/main/java/org/tron/common/logsfilter/ContractEventParser.java | Adds stricter bounds checks and rejects negative lengths in dynamic ABI decoding. |
| framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpcImpl.java | Introduces shared tryDecodeRevertReason() and applies it to JSON-RPC failure paths. |
| framework/src/test/java/org/tron/common/logsfilter/EventParserTest.java | Adds focused tests for subBytes() bounds and negative/malicious ABI fields. |
| framework/src/test/java/org/tron/core/services/jsonrpc/TronJsonRpcRevertReasonTest.java | Adds tests ensuring revert reason decoding fails closed on malicious ABI lengths and succeeds on valid input. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a12157f to
01015a2
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
What does this PR do?
This PR hardens ABI decoding for malformed dynamic data in both contract event parsing and JSON-RPC revert reason handling.
It:
ContractEventParsereth_callandeth_estimateGastryDecodeRevertReasonto centralize duplicated revert error handling used byeth_callandeth_estimateGasWhy are these changes required?
Previously, malformed ABI payloads could:
subBytes()with invalid offsets or oversized lengthsstring/byteseth_callandeth_estimateGasThis PR has been tested by:
:framework:test --tests org.tron.common.logsfilter.EventParserTest:framework:test --tests org.tron.core.services.jsonrpc.TronJsonRpcRevertReasonTesteth_calleth_estimateGasFollow up
Extra details
Summary by cubic
Strengthens ABI parsing bounds and revert reason decoding. Adds tests to cover all
parseDataBytestype branches and revert parsing used byeth_callandeth_estimateGas.Bug Fixes
ContractEventParser: reject empty sources; out-of-range/negative offsets and lengths; prevent truncation insubBytes; reject negative dynamic lengths; decodestringwith UTF-8.Error(string)selector, ignore short/malformed data, and cap payload at 4KB.Refactors
TronJsonRpcImpl.tryDecodeRevertReasonand used ineth_callandeth_estimateGas.parseDataBytes(all types), revert reason limits, and JSON-RPC error paths.Written for commit 17e9cc2. Summary will update on new commits.
Summary by CodeRabbit
Release Notes
Bug Fixes
Tests