diff --git a/CHANGELOG.md b/CHANGELOG.md index 738ec669..8782286b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -113,6 +113,7 @@ - fix: replace assert with isinstance guard in get_callee for invalid MethodSpec tokens @williballenthin - fix: assign ConfigDict to model_config in ConciseModel so extra="ignore" is actually applied @williballenthin (SURF-42) - fix: replace assert with isinstance guard in get_callee for invalid MethodSpec tokens @williballenthin (SURF-41) +- fix: incorrect bytes() constructor usage in buf_filled_with @mike-hunhoff #3077 - fix: remove redundant code related to cli loading @mike-hunhoff #3076 ### capa Explorer Web diff --git a/capa/features/extractors/strings.py b/capa/features/extractors/strings.py index 04a28f64..5019eadd 100644 --- a/capa/features/extractors/strings.py +++ b/capa/features/extractors/strings.py @@ -57,7 +57,7 @@ def buf_filled_with(buf: bytes, character: int) -> bool: return all(b == character for b in buf) # single big allocation, re-used each loop - dupe_chunk = bytes(character) * SLICE_SIZE + dupe_chunk = bytes([character]) * SLICE_SIZE for offset in range(0, len(buf), SLICE_SIZE): # bytes objects are immutable, so the slices share the underlying array, diff --git a/tests/test_strings.py b/tests/test_strings.py index 727af67d..ce31b9c9 100644 --- a/tests/test_strings.py +++ b/tests/test_strings.py @@ -34,6 +34,12 @@ def test_buf_filled_with(): assert buf_filled_with(b"", 0x00) is False # Empty buffer assert buf_filled_with(b"\x00", 0x00) is True # Single byte + # Large buffers (exercise chunked processing) + assert buf_filled_with(b"A" * 5000, ord("A")) is True + assert buf_filled_with(b"A" * 5000 + b"B", ord("A")) is False + assert buf_filled_with(b"\xff" * 5000, 0xFF) is True + assert buf_filled_with(b"\x00" * 5000, 0x00) is True + def test_extract_ascii_strings(): # test empty buffer