Skip to content

Framework: allow string reads that end on the last byte of a data layer - #2109

Open
Dukotah wants to merge 1 commit into
volatilityfoundation:developfrom
Dukotah:fix-address-to-string-last-byte
Open

Dukotah wants to merge 1 commit into
volatilityfoundation:developfrom
Dukotah:fix-address-to-string-last-byte

Conversation

@Dukotah

@Dukotah Dukotah commented Nov 20, 2026

Copy link
Copy Markdown

What was wrong

gather_contiguous_bytes_from_address() (used by address_to_string() and pointer_to_string()) has a branch for data layers that are not translation layers. That branch checks starting_address + count < data_layer.maximum_address. maximum_address is the last valid address, and it is inclusive. A read of count bytes ends at starting_address + count - 1. So a read that ends exactly on the last byte of the layer was rejected as out of range.

Repro

ctx = contexts.Context()
ctx.add_layer(physical.BufferDataLayer(ctx, "cfg", "buf", b"hello\x00"))
# maximum_address == 5, len == 6
utility.address_to_string(ctx, "buf", 0, 6)   # InvalidAddressException
utility.address_to_string(ctx, "buf", 0, 5)   # InvalidAddressException
utility.address_to_string(ctx, "buf", 0, 3)   # 'hel'

Fix

Compare the last byte read against maximum_address: starting_address + count - 1 <= data_layer.maximum_address. This matches the bounds check in BufferDataLayer.is_valid(). Reads past the end of the layer still raise.

Testing

Added test/test_objects_utility.py. It reads 3, 5 and 6 bytes from a 6 byte buffer, and checks that a 7 byte read still raises. Without the fix, the 5 and 6 byte cases fail. With it, these and test/test_linux_socket_addresses.py pass (28 passed). ruff check and ruff format --check are clean on both files.

Dukotah

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