Repository navigation
gen_match: don't crash on bytes patterns containing a dot - #118
Open
rootkiller6788 wants to merge 3 commits into
Open
rootkiller6788 wants to merge 3 commits into
rootkiller6788 wants to merge 3 commits into
Conversation
added 3 commits
September 14, 2026 01:29
_ANY always appended the str "a", so a bytes pattern like b"a.c" blew up with "can't concat str to bytes" when the regex hook was enabled. Route it through to_correct_type like the other branches.
The existing bytes tests all used literals only, so nothing caught the _ANY path. Both new cases fail before the previous commit.
The second half of that message wasn't an f-string, so users got the
literal text {_pattern!r} instead of the regex. Drop the stray
underscore too, the parameter is called pattern.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
rootkiller6788
marked this pull request as ready for review
November 18, 2026 13:19
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.
Found this while reading the regex match generator: the
.case always built astr, so any bytes pattern with a dot blew up.Reproduce with the regex hook on:
The exception isn't caught, it comes straight out of
gen_matchwhilere._compileis hooked, so the user just sees theirre.compilecall fail. Bytes patterns are pretty common when fuzzing binary formats, and a dot in one isn't unusual._ANYnow goes throughto_correct_type, same as_RANGEand_CATEGORYa few lines below. I added two bytes cases to regex_match_generation_test.py — the three bytes tests that were already there only used literals, so nothing hit this path.While I was in there I noticed the "generated match did not match" warning wasn't an f-string on its second line, so instead of the pattern it printed the literal text
{_pattern!r}. Fixed that in a separate commit (the variable ispattern).Tested on 3.12.5 and 3.14.3. I couldn't build the native extension locally, so I ran the python-level suites against a stub of the native module: regex_match_generation_test (34) and instrument_bytecode_test (25) pass, ruff check src is clean. The stubbed run can't exercise str_hook_test / regex_coverage_test since those need the real native hooks.