Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions test/test_objects_utility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Reading strings that end on the last byte of a data layer."""

import pytest

from volatility3.framework import contexts, exceptions
from volatility3.framework.layers import physical
from volatility3.framework.objects import utility


def _context_with_buffer(data: bytes) -> contexts.Context:
context = contexts.Context()
context.add_layer(physical.BufferDataLayer(context, "config", "buffer", data))
return context


@pytest.mark.parametrize("count", [3, 5, 6])
def test_address_to_string_reaches_last_byte(count):
"""A read ending exactly on the layer's last byte is in bounds."""
context = _context_with_buffer(b"hello\x00")
assert utility.address_to_string(context, "buffer", 0, count) == "hello"[:count]


def test_address_to_string_past_end_still_fails():
context = _context_with_buffer(b"hello\x00")
with pytest.raises(exceptions.InvalidAddressException):
utility.address_to_string(context, "buffer", 0, 7)
2 changes: 1 addition & 1 deletion volatility3/framework/objects/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def gather_contiguous_bytes_from_address(

last_address = address + length

elif starting_address + count < data_layer.maximum_address:
elif starting_address + count - 1 <= data_layer.maximum_address:
data = data_layer.read(starting_address, count)

# if we were able to read from the first page, we want to try and construct the string
Expand Down