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(commit): bound co_authors trailer parsing by Keerthana-64 · Pull Request #2257 · gitpython-developers/GitPython

Conversation

@Keerthana-64

@Keerthana-64 Keerthana-64 commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Repro: read Commit.co_authors on a commit whose message has a Co-authored-by: line that repeats < without ever closing a > (a few hundred KB on that one line is enough). A 60 KB line already burns several seconds of CPU; larger reaches minutes.

Cause: ^Co-authored-by: (.*) <(.*?)>$ lets the greedy (.*) backtrack over every < position, and for each one the lazy (.*?) rescans to end of line looking for a > that never arrives, so the match is O(n^2) in the line length. The message is decoded straight from the object bytes in _deserialize, so it is fully attacker-controlled by any repository whose commits you inspect.

Fix: parse each Co-authored-by: line with string operations instead of a backtracking regex. A trailer is Co-authored-by: <name> <email> with the email in the final angle brackets, so the name ends at the last < and the line ends at >. This is linear and reproduces the old results exactly: I compared it against the previous pattern over ~1.8M fuzzed inputs (names/emails with spaces, extra </>, trailing text, CR, unicode, multi-line) with zero differences, and the existing test_commit_co_authors cases are unchanged. The crafted input drops from seconds to microseconds.

Added test_commit_co_authors_bounds_malformed_trailer, a CPU-time regression that fails on the old code and passes here, and it also checks a well-formed trailer on a later line is still parsed.

I'm 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(commit): bound co_authors trailer parsing
07e9720
`Commit.co_authors` matched `^Co-authored-by: (.*) <(.*?)>$` against the
whole commit message. On a single trailer line that repeats `` <`` without
ever closing a `>`, the greedy `(.*)` backtracks over every `` <`` position
and, for each, the lazy `(.*?)` rescans to the end of the line looking for a
`>` that never arrives. That is O(n^2) in the length of the line.

The commit message is fully attacker-controlled: it comes straight from the
object bytes decoded in `_deserialize`, so a repository can ship a commit
whose message is a few hundred KB of `Co-authored-by: a <a <a <...`. Any
caller that reads `commit.co_authors` (a public property) then stalls. A
60 KB line already costs several seconds of CPU; a few hundred KB reaches
minutes.

Parse each `Co-authored-by:` line with string operations instead of a
backtracking regex: a trailer is `Co-authored-by: <name> <email>` with the
email in the final angle brackets, so the name ends at the last `` <`` and
the line ends at `>`. This reproduces the previous results exactly
(verified against the old pattern over ~1.8M fuzzed inputs, including the
existing `test_commit_co_authors` cases) while running in linear time: the
same crafted input drops from seconds to microseconds.

Add a CPU-time regression test that fails on the old code and passes here,
and confirm a well-formed trailer on a later line is still parsed.
@Byron
Byron requested a balanced review from Copilot September 29, 2026 11:37
Copilot started reviewing on behalf of Byron September 29, 2026 11:38
View session
Copilot AI reviewed Sep 29, 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 implementation preserves parsing behavior while eliminating quadratic backtracking with focused regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Replaces vulnerable quadratic regex parsing with linear string parsing for co-author trailers.

Changes:

  • Parses trailers using prefix, suffix, and final-separator checks.
  • Adds a CPU-time regression test for malformed input.
File Description
git/​objects/​commit.py Implements bounded co-author parsing.
test/​test_commit.py Tests malformed and subsequent valid trailers.

💡 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 29, 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!

I ran additional reviews against it and it came up empty.
I myself gave it an armchair review, and feel reminded of the various other regex-related performance issues that were fixed recently.

Sorry, something went wrong.

Uh oh!

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

All reactions
@Byron
Byron merged commit f8776ee into gitpython-developers:main Sep 29, 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.

3 participants

@Keerthana-64 @Byron
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 01402503 — 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.