incorrect bytes() constructor usage in buf_filled_with#3077
Merged
Conversation
There was a problem hiding this comment.
Please add bug fixes, new features, breaking changes and anything else you think is worthwhile mentioning to the master (unreleased) section of CHANGELOG.md. If no CHANGELOG update is needed add the following to the PR description: [x] No CHANGELOG update needed
CHANGELOG updated or no update needed, thanks! 😄
Contributor
There was a problem hiding this comment.
Code Review
This pull request fixes a bug in the buf_filled_with function where the comparison chunk was incorrectly initialized, and adds new test cases to verify behavior with large buffers. The reviewer suggested further improving test coverage by adding specific cases that target potential boundary issues in the chunked processing logic.
mr-tz
approved these changes
May 16, 2026
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.
Bug Fix: Incorrect
bytes()constructor usage inbuf_filled_withDescription
In
capa/features/extractors/strings.py:buf_filled_with, the code usedbytes(character) * SLICE_SIZEto create a repeating chunk of a specific character. However, in Python 3,bytes(int)creates a null-filled buffer of that length, rather than a single byte with that value.This caused the chunked comparison for large buffers (>= 4096 bytes) to fail for characters in the
REPEATSset (like'A',0xFE,0xFF), because the constructeddupe_chunkhad an incorrect length and content. This effectively disabled the optimization intended to skip large blocks of filler data (like section padding), causing unnecessary regex scanning overhead.Fix
Changed
bytes(character)tobytes([character])to correctly create a 1-byte buffer containing the character value before multiplying bySLICE_SIZE.Tests
Added unit tests in
tests/test_strings.pywith buffers larger than 4096 bytes to ensure coverage of the chunked processing logic inbuf_filled_with.Checklist