Skip to content

Do not lift past the end of data when bytes_offset is set - #606

Merged
twizmwazin merged 1 commit into
angr:masterfrom
NopeCharon:fix/lift-bytes-offset-window
Nov 16, 2026
Merged

twizmwazin merged 1 commit into
angr:masterfrom
NopeCharon:fix/lift-bytes-offset-window

Conversation

@NopeCharon

Copy link
Copy Markdown
Contributor

Fixes #482.

lift() capped max_bytes at len(data), but the lift window starts at bytes_offset, so a block near the end of the buffer could run up to bytes_offset bytes past it. libVEX then decoded the 8 bytes of NUL padding and whatever came after them. With the input from the issue (48 bytes, bytes_offset=36), master lifts more than the 12 bytes that are left: bytes input gives 18 instructions and bytearray/memoryview give 20. Those instructions are not in the input, and the result changes with the input type.

This caps max_bytes at the number of bytes left after the block start (len(data) - bytes_offset). For ARM THUMB, addr and bytes_offset both carry the THUMB bit, so the block starts at bytes_offset - 1. The existing skip logic already handled that for the Python lifters. That start offset is now computed once and used for both the cap and the Python lifters' slice. A bytes_offset at or past the end of data now raises PyVEXError, the same as other empty inputs.

Pointer (cffi) inputs are unchanged because their length is unknown; max_bytes is still required there.

Test: test_max_bytes_with_bytes_offset in tests/test_lift.py covers the issue's case for bytes/bytearray/memoryview, with and without max_bytes. It also covers the past-the-end error and a THUMB block that ends at the end of the buffer. It fails on master (18 == 12), and the full test suite passes with the change.

lift() bounded max_bytes by len(data), but the lift window starts at
bytes_offset, so a block starting near the end of the buffer was allowed
to run up to bytes_offset bytes past it. libVEX then decoded the 8 bytes
of NUL padding and whatever followed them in memory, producing blocks
with instructions that are not in the input and that differ between
bytes and bytearray/memoryview inputs.

Bound max_bytes by the bytes that remain after the block start instead.
For ARM THUMB code, where addr and bytes_offset both carry the THUMB bit,
the block starts one byte before bytes_offset; compute that start once
and reuse it for the Python lifters' slice as well. A bytes_offset at or
past the end of data now raises PyVEXError like other empty inputs.

Fixes angr#482.
@twizmwazin
twizmwazin merged commit e070fbb into angr:master Nov 16, 2026
22 checks passed
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.

OOB read in lift when using bytes_offset parameter

2 participants