GitHub Advisoryadvisory · PyPI
GHSA-m64x-33q8-m5h7 GitPython parse_actor_and_date() is vulnerable to quadratic backtracking on malformed identity lines
HIGH
Official page ↗
- Ecosystem
- PyPI
- Packages
- GitPython
- Severity
- High
- CVSS vector
- CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
- Weaknesses
- CWE-1333
- Reviewed
- 2026-10-27
Affected packages
• PyPI GitPython: < 3.2.0 → fixed in 3.2.0
Description
Summary
This is a residual of GHSA-g5vv-9gxw-82hx / CVE-2026-87819. The 3.1.60 fix made `Actor._from_string` regex-free, but `parse_actor_and_date` still runs `_re_actor_epoch` on the same author/committer/tagger line one step earlier. That pattern backtracks quadratically when the trailing epoch or timezone is missing or malformed, so the same class of slow parse is still reachable in 3.1.62.
Details
`git/objects/util.py:322`:
```python
_re_actor_epoch = re.compile(r"^.+? (.*) (\d+) ([+-]\d+).*$")
```
`.+?` and `(.*)` can both absorb the same run of spaces, and the required ` (\d+) ([+-]\d+)` tail is only checked after them. On a long line with no valid tail, the search retries every split point.
It is called from `parse_actor_and_date` (`git/objects/util.py:335`), which runs on the author and committer lines in `Commit._deserialize` (`git/objects/commit.py:917`, `:931`) and on the tagger line in `git/objects/tag.py:129`.
The published payload (letters plus an unterminated ` Tuple[int, int]:
# Precompiled regexes
-_re_actor_epoch = re.compile(r"^.+? (.*) (\d+) ([+-]\d+).*$")
-_re_only_actor = re.compile(r"^.+? (.*)$")
+# The leading field name ("author", "committer", "tagger") is matched with ``.[^ ]*`` rather than
+# ``.+?``: both stop at the first space after the first character, but ``.[^ ]*`` cannot overlap the
+# following ``(.*)``, so a line with no valid trailing epoch/offset no longer backtracks quadratically.
+_re_actor_epoch = re.compile(r"^.[^ ]* (.*) (\d+) ([+-]\d+).*$")
+_re_only_actor = re.compile(r"^.[^ ]* (.*)$")
def parse_actor_and_date(line: str) -> Tuple[Actor, int, int]:
diff --git a/test/test_util.py b/test/test_util.py
index cf4299d5..e1631420 100644
--- a/test/test_util.py
+++ b/test/test_util.py
@@ -22,6 +22,7 @@ from git.cmd import dashify
from git.objects.util import (
altz_to_utctz_str,
from_timestamp,
+ parse_actor_and_date,
parse_date,
tzoffset,
utctz_to_altz,
@@ -571,6 +572,30 @@ class TestUtils(TestBase):
Actor("name last another", "[email protected]"),
)
+ def test_parse_actor_and_date_malformed_line_is_linear(self):
+ # A long author line whose trailing epoch/offset is missing or malformed used to make
+ # _re_actor_epoch backtrack quadratically: ~7 s per Commit.author access for a 32 KB line.
+ # The parse result must be unchanged; only the time spent reaching it should move.
+ for tail in ("", " notanumber -0700", " 1191999972", " -0700", " 1191999972 xx"):
+ line = "author " + " " * 32000 + tail
+ start = time.perf_counter()
+ actor, epoch, offset = parse_actor_and_date(line)
+ self.assertLess(time.perf_counter() - start, 1.0)
+ self.assertEqual(epoch, 0)
+ self.assertEqual(offset, 0)
+
+ # Well-formed lines, including one with a long name, still parse exactly as before.
+ actor, epoch, offset = parse_actor_and_date(
+ "author Tom Preston-Werner 1191999972 -0700"
+ )
+ self.assertEqual(actor, Actor("Tom Preston-Werner", "[email protected]"))
+ self.assertEqual(epoch, 1191999972)
+ self.assertEqual(offset, 25200)
+
+ actor, epoch, offset = parse_actor_and_date("author " + "a " * 16000 + " 1 -0700")
+ self.assertEqual(actor.email, "a@b")
+ self.assertEqual(epoch, 1)
+
@ddt.data(
("name", ""),
("name", "prefix_"),
```
Found with AI assistance (Claude) and verified by hand.
Brian Willows
Related
Weakness · CWE (1)
- CWE-1333 Inefficient Regular Expression Complexity weakness
References
- https://github.com/gitpython-developers/GitPython/security/advisories/GHSA-m64x-33q8-m5h7 web
- https://github.com/gitpython-developers/GitPython/pull/2253 web
- https://github.com/gitpython-developers/GitPython/commit/8290c98d35465a38090cdcc1b17be69967092a15 web
- https://github.com/gitpython-developers/GitPython package
- https://github.com/gitpython-developers/GitPython/releases/tag/3.2.0 web