Reject truncated RLP and trailing data when decoding - #32
Merged
Merged
Conversation
The decoder silently accepted items shorter than their declared length (e.g. 0x83646f -> "646f", 0xc3 -> []), children that overran their parent list (0xc2836400 -> ["64"]), and ignored bytes after the top-level item (0x0102 -> "01"). Check the available length in the short string, long string and short list branches (the long list branch already did), and throw when data remains after the top-level item. Add regression vectors for truncated and trailing input. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #32 +/- ##
============================================
+ Coverage 82.11% 84.27% +2.15%
- Complexity 55 59 +4
============================================
Files 3 3
Lines 151 159 +8
============================================
+ Hits 124 134 +10
+ Misses 27 25 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
The decoder silently accepted malformed input:
Each case now throws a RuntimeException, as ethers.js does. Every item's size is checked against the available data, and decode() rejects anything left after the top-level item.
Behavior change: input that used to decode silently now throws. That includes odd-length hex such as 0x123, which was padded and partly ignored. Correct RLP decodes the same as before.
Adds 19 regression vectors for truncated and trailing input.
🤖 Generated with Claude Code (https://claude.com/claude-code)