Repository navigation
fix(google-cloud-bigquery): avoid regex ReDoS and fix lexer escapes - #19300
Draft
julianxu-goog wants to merge 1 commit into
Draft
julianxu-goog wants to merge 1 commit into
julianxu-goog wants to merge 1 commit into
Conversation
- Anchor `_PROJECT_PREFIX_PATTERN` and exclude colons/whitespace from its domain prefix to avoid polynomial backtracking in `_split_id`. - Add a negative lookbehind `(?<!%)` before `(%*)%` in `_extract_types` to avoid polynomial backtracking on long runs of `%` characters. - Fix raw-string escape matching (`\.` -> `\\.`) in `PY_STRING` inside `magics/line_arg_parser/lexer.py` so escaped quotes and backslashes tokenize properly. Fixes internal issue b/581933482
Contributor
There was a problem hiding this comment.
Code Review
This pull request addresses potential Regular Expression Denial of Service (ReDoS) vulnerabilities and backtracking issues across several regex patterns. Specifically, it updates the project prefix pattern in _helpers.py to prevent polynomial backtracking on malformed IDs, refactors the percent-sign matching in cursor.py to avoid backtracking, and corrects the string escaping pattern in the lexer. Additionally, comprehensive unit tests are added to verify these fixes and ensure performance remains stable under pathological inputs. No review comments were provided, so there is no feedback to address.
This branch has not been deployed
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.
Fixes three regex issues in
google-cloud-bigquery:_PROJECT_PREFIX_PATTERN(google/cloud/bigquery/_helpers.py): Replace(?P<project_id>\S+\:[^.]+)with^(?P<project_id>[^:\s]+:[^.\s]+)so inputs with many colons do not triggerO(N^2)backtracking in_split_id._extract_types(google/cloud/bigquery/dbapi/cursor.py): Add(?<!%)before(%*)%so long runs of%characters do not triggerO(N^2)backtracking while preserving identical matching behavior.PY_STRING(google/cloud/bigquery/magics/line_arg_parser/lexer.py): Fix raw-string escape sequence\.to\\.so escaped quotes and backslashes in--paramsstring literals tokenize properly.Testing
nox -r -s lintnox -r -s "unit-3.14(test_type='unit')"(2967 passed, 2 skipped)Fixes internal issue b/581933482