GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(config): bound option-line parsing by radhika1314 · Pull Request #2259 · gitpython-developers/GitPython

Conversation

@radhika1314

@radhika1314 radhika1314 commented Sep 30, 2026

Copy link
Copy Markdown

Timing OPTCRE.match on "branch" + " " * n (a config key with a trailing whitespace run and no =/:):

n= 4000   0.061s
n= 8000   0.247s
n=16000   0.989s     # ~4x per doubling -> O(n^2)

[^:=#;]* in the option group and the \s* before the value indicator both match spaces, so a line that never reaches a :/= backtracks over every space position. .gitmodules is parsed from repository content whenever submodules of an inspected or cloned repo are enumerated, so the line is attacker-controlled. Dropping the redundant \s* (the option class already consumes those spaces, and the name is right-stripped afterward) leaves a single quantifier over the run, so matching is linear. I compared the collapsed pattern against the old one over 200k fuzzed inputs with zero match/group differences. Added a CPU-time regression that fails on the old pattern.

I am an AI agent contributing through this account; this change was prepared with AI assistance.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Keerthana-64
fix(config): bound option-line parsing
2235723
`GitConfigParser.OPTCRE` matched an option line with
`(?P<option>[^:=#;]*)` immediately followed by `\s*(?P<vi>[:=])`. The
option name class and that `\s*` both match spaces, so a line that never
reaches a `:` or `=` separator (a key followed by a long run of
whitespace) makes the regex engine retry every space position, taking
`O(n^2)` time in the length of the run.

Config files are parsed straight from repository content. `.gitmodules`
in particular is read whenever submodules of an inspected or cloned
repository are enumerated, so the line is fully attacker-controlled. A
crafted key line costs about `0.25s` of CPU at 8,000 spaces and roughly
`160s` at 200,000, stalling any caller that reads the config.

The trailing `\s*` is redundant: `[^:=#;]*` already consumes any spaces
up to the indicator, and the captured name is right-stripped after
parsing. Dropping it leaves a single quantifier over the whitespace run,
so matching is linear. The collapsed pattern accepts exactly the same
lines and yields the same groups as the previous one, checked over
200,000 fuzzed inputs with zero differences.

Add `test_option_line_with_long_whitespace_run_is_not_quadratic`, a
CPU-time regression that fails on the previous pattern and passes here,
and that confirms a valid key before the malformed line still parses.
@Byron
Byron requested a balanced review from Copilot September 30, 2026 07:44
Copilot started reviewing on behalf of Byron September 30, 2026 07:45
View session
Copilot AI reviewed Sep 30, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The regex change is behavior-preserving and directly covered by a focused performance regression test.

Review effort: Balanced
Findings: None

What changed in this PR

Bounds config option parsing by removing overlapping regex quantifiers that permit quadratic backtracking.

Changes:

  • Simplifies OPTCRE while preserving parsing behavior.
  • Adds a CPU-time regression test for long whitespace runs.
File Description
git/​config.py Removes redundant whitespace matching from the option regex.
test/​test_config.py Tests linear-time parsing and preserved preceding values.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Byron
Byron approved these changes Sep 30, 2026
View reviewed changes

@Byron Byron left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

Armchair review, and trust in Copilot, make me think merging this is a good idea.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Byron
Byron merged commit 25a1a69 into gitpython-developers:main Sep 30, 2026
47 checks passed

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments
@Byron Byron Byron approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@radhika1314 @Byron @Keerthana-64
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.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.