Skip to content

Fix integer overflow in heap_opt range walk on top-of-memory access (… - #582

Open
kvpanch wants to merge 1 commit into
mainfrom
kvpanch/gh_581
Open

Fix integer overflow in heap_opt range walk on top-of-memory access (…#582
kvpanch wants to merge 1 commit into
mainfrom
kvpanch/gh_581

Conversation

@kvpanch

@kvpanch kvpanch commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

#581)

The word-stepping loops in taint_range, mark_escaping_range, and mark_escaping_and_tainted_range walked a static range with while word < end { word += 32 }. When an access sits near the top of the address space, end = address.saturating_add(size) saturates at u64::MAX, and the final word += 32 steps past u64::MAX, panicking with "attempt to add with overflow".

Under --newyork this is reachable from valid Yul: folding add(mul(MAX_U256, 1), 0x41) to 0x40 lets an mstore corrupt the free-memory-pointer word with u64::MAX; mem_opt then forwards mload(0x40) to that literal, turning a later mstore(fmp, _) into a static unaligned store at u64::MAX that taints its covered words.

Iterate the already-bounded num_words count with a saturating step so the walk covers the same words without overflowing.

…581)

The word-stepping loops in `taint_range`, `mark_escaping_range`, and
`mark_escaping_and_tainted_range` walked a static range with
`while word < end { word += 32 }`. When an access sits near the top of
the address space, `end = address.saturating_add(size)` saturates at
`u64::MAX`, and the final `word += 32` steps past `u64::MAX`, panicking
with "attempt to add with overflow".

Under `--newyork` this is reachable from valid Yul: folding
`add(mul(MAX_U256, 1), 0x41)` to `0x40` lets an mstore corrupt the
free-memory-pointer word with `u64::MAX`; mem_opt then forwards
`mload(0x40)` to that literal, turning a later `mstore(fmp, _)` into a
static unaligned store at `u64::MAX` that taints its covered words.

Iterate the already-bounded `num_words` count with a saturating step so
the walk covers the same words without overflowing.
@kvpanch
kvpanch requested review from elle-j and xermicus July 28, 2026 14:06
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