Skip to content

fix(bytecode): preserve iterator position after truncated push#3800

Open
pengqima wants to merge 1 commit into
bluealloy:mainfrom
pengqima:fix/bytecode-iterator-position
Open

fix(bytecode): preserve iterator position after truncated push#3800
pengqima wants to merge 1 commit into
bluealloy:mainfrom
pengqima:fix/bytecode-iterator-position

Conversation

@pengqima

Copy link
Copy Markdown

Summary

Make BytecodeIterator::skip_immediate consume at most the bytes that remain, keeping an exhausted iterator anchored to the original bytecode slice.

This is a follow-up to #3792.

Problem

After #3792 switched BytecodeIterator to the original unpadded legacy bytecode, a truncated PUSH can make get(immediate_size..) return None.

The previous unwrap_or_default() fallback then creates an empty slice unrelated to the original bytecode allocation. A later call to position() uses offset_from_unsigned relative to the original start pointer, which requires both pointers to belong to the same allocation.

Fix

Slice at min(immediate_size, remaining.len()) instead. This preserves the existing iteration behavior—all available immediate bytes are consumed and iteration ends—while retaining the original slice provenance.

A regression test covers calling position() after a partially truncated PUSH2.

Testing

  • cargo fmt --all --check
  • cargo test -p revm-bytecode --all-features
  • cargo clippy -p revm-bytecode --all-targets --all-features -- -D warnings
  • cargo check -p revm-bytecode --no-default-features

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant