Repository navigation
Do not lift past the end of data when bytes_offset is set - #606
Merged
Merged
Conversation
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.
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.
Fixes #482.
lift()cappedmax_bytesatlen(data), but the lift window starts atbytes_offset, so a block near the end of the buffer could run up tobytes_offsetbytes 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:bytesinput gives 18 instructions andbytearray/memoryviewgive 20. Those instructions are not in the input, and the result changes with the input type.This caps
max_bytesat the number of bytes left after the block start (len(data) - bytes_offset). For ARM THUMB,addrandbytes_offsetboth carry the THUMB bit, so the block starts atbytes_offset - 1. The existingskiplogic 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. Abytes_offsetat or past the end ofdatanow raisesPyVEXError, the same as other empty inputs.Pointer (cffi) inputs are unchanged because their length is unknown;
max_bytesis still required there.Test:
test_max_bytes_with_bytes_offsetintests/test_lift.pycovers the issue's case forbytes/bytearray/memoryview, with and withoutmax_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.