Repository navigation
Conversation
…hon 3 The brute-force fallback of mso_file_extract (used to recover MSO/ActiveMime containers when neither the header hint nor the known fixed offsets 0x32 / 0x22A point at the zlib stream) applied the str regex pattern re_zlib_header to bytes data, raising 'TypeError: cannot use a string pattern on a bytes-like object' on Python 3 instead of recovering the payload. Use a bytes pattern, which works on both Python 2 and 3. Reproduction: build an ActiveMime container whose zlib stream is at an offset other than the header hint / 0x32 / 0x22A (e.g. a hand-crafted MHTML sample), and run olevba on it: the extraction crashes instead of finding the embedded VBA project. Add a regression test (tests/olevba/test_mso_file_extract.py) covering the standard Word header layout and the brute-force fallback.
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.
Summary
The brute-force fallback of
mso_file_extract— used to recover MSO/ActiveMime containers when neither the header hint (u16 at 0x1E) nor the known fixed offsets (0x32, 0x22A) point at the zlib stream — applies the str regex patternre_zlib_headerto bytes data:On Python 3 this raises
TypeError: cannot use a string pattern on a bytes-like objectinstead of recovering the payload, so the whole extraction (and therefore VBA discovery in olevba) fails for such files.Reproduction
Build an ActiveMime container whose zlib stream is at an offset other than the header hint / 0x32 / 0x22A — e.g. a hand-crafted MHTML sample — and run olevba on it:
Encountered with a hand-built MHTML + ActiveMime test sample whose header did not follow the Word convention.
Fix
One line: make the pattern bytes (
re.compile(b'x')), which works on both Python 2 and 3.Tests
Added
tests/olevba/test_mso_file_extract.py:TypeErroron unpatched master, passes with this fix.Both tests pass locally (Python 3.13, pytest).