Repository navigation
fix(bytecode): avoid out-of-bounds pointer in analyze_legacy - #3752
Merged
Merged
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
Merged
RealiCZ
added a commit
to megaeth-labs/revm
that referenced
this pull request
Sep 18, 2026
…lloy#3746 bluealloy#3802 bluealloy#3864 (#54) Co-authored-by: Prajjwal Chittori <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Co-authored-by: Anders Brownworth <[email protected]> Co-authored-by: Ivan Wang <[email protected]> Co-authored-by: cui <[email protected]>
14 tasks done
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
analyze_legacy advances its cursor with raw-pointer arithmetic:
iterator = unsafe { iterator.add(push_offset as usize + 2) };
When bytecode ends mid-PUSH (e.g. a trailing PUSH32), this computes a pointer up to 33 bytes past the end of the bytecode allocation. The pointer is never dereferenced — the while iterator < end guard stops any read — but pointer::add (https://doc.rust-lang.org/std/primitive.pointer.html#method.add) requires the result to stay within (or one past) the same allocation, so forming the out-of-bounds pointer is undefined behavior in its own right.
Fix
Use wrapping_add, which is always defined to compute and is bit-identical on real targets:
iterator = iterator.wrapping_add(push_offset as usize + 2);
The push_overflow = (iterator as usize) - (end as usize) calculation that relies on the past-end value is unchanged, and the < end guard still prevents any out-of-bounds read.
Impact
No behavior change on current targets and no known exploit: the value is only compared and address-subtracted, never read out of bounds, and analyze_legacy's output is unaffected. This is a soundness fix — it removes UB that a future compiler (or a non-standard/zkVM backend) would be free to miscompile.
How it was found
Surfaced by a Kani (CBMC) proof harness for analyze_legacy, which flags the pointer::add precondition violation (Miri catches it too).
Testing
The existing analyze_legacy unit tests pass unchanged — the fix is behavior-preserving (including test_bytecode_with_max_push32).