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 — Harden diff path and actor identity parsing by Byron · Pull Request #2215 · gitpython-developers/GitPython

Harden diff path and actor identity parsing #2215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Byron merged 2 commits into main from various-fixes
Aug 11, 2026

Uh oh!

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

Merged

Harden diff path and actor identity parsing #2215

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
2 commits
Select commit Hold shift + click to select a range
9a92677
fix: decode quoted diff paths in one pass
Byron Aug 11, 2026
751473a
fix: parse actor identities without regular expressions
Byron Aug 11, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

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

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

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

Diff view
Diff view

There are no files selected for viewing

13 changes: 13 additions & 0 deletions 13 doc/source/changes.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
Changelog
=========

3.1.60
======

Security fixes for

* https://github.com/gitpython-developers/GitPython/security/advisories/GHSA-g5vv-9gxw-82hx

If you can, also try and provide feedback on the upcoming v4 branch
https://github.com/gitpython-developers/GitPython/pull/2177 - patches welcome.

See the following for all changes.
https://github.com/gitpython-developers/GitPython/releases/tag/3.1.60

3.1.59
======

Expand Down
39 changes: 29 additions & 10 deletions 39 git/diff.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,43 @@ class DiffConstants(enum.Enum):
:const:`git.INDEX` and :const:`Diffable.INDEX`, as well as :const:`Diffable.Index`.
"""

_octal_byte_re = re.compile(rb"\\([0-9]{3})")


def _octal_repl(matchobj: Match) -> bytes:
value = matchobj.group(1)
value = int(value, 8)
value = bytes(bytearray((value,)))
return value
def _unquote_path(path: bytes) -> bytes:
result = bytearray()
escapes = {
ord("a"): 7,
ord("b"): 8,
ord("f"): 12,
ord("n"): 10,
ord("r"): 13,
ord("t"): 9,
ord("v"): 11,
}
i = 0
while i < len(path):
if path[i] != ord("\\") or i + 1 == len(path):
result.append(path[i])
i += 1
continue
if path[i + 1] in b"0123" and i + 3 < len(path) and all(c in b"01234567" for c in path[i + 2 : i + 4]):
result.append(int(path[i + 1 : i + 4], 8))
i += 4
continue
escaped = path[i + 1]
if escaped in escapes or escaped in b'\\"':
result.append(escapes.get(escaped, escaped))
else:
result.extend(path[i : i + 2])
i += 2
return bytes(result)


def decode_path(path: bytes, has_ab_prefix: bool = True) -> Optional[bytes]:
if path == b"/dev/null":
return None

if path.startswith(b'"') and path.endswith(b'"'):
path = path[1:-1].replace(b"\\n", b"\n").replace(b"\\t", b"\t").replace(b'\\"', b'"').replace(b"\\\\", b"\\")

path = _octal_byte_re.sub(_octal_repl, path)
path = _unquote_path(path[1:-1])

if has_ab_prefix:
assert path.startswith(b"a/") or path.startswith(b"b/")
Expand Down
24 changes: 8 additions & 16 deletions 24 git/util.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -858,10 +858,6 @@ class Actor:
committers and authors or anything with a name and an email as mentioned in the git
log entries."""

# PRECOMPILED REGEX
name_only_regex = re.compile(r"<(.*)>")
name_email_regex = re.compile(r"(.*) <(.*?)>")

# ENVIRONMENT VARIABLES
# These are read when creating new commits.
env_author_name = "GIT_AUTHOR_NAME"
Expand Down Expand Up @@ -906,18 +902,14 @@ def _from_string(cls, string: str) -> "Actor":
:return:
:class:`Actor`
"""
m = cls.name_email_regex.search(string)
if m:
name, email = m.groups()
return Actor(name, email)
else:
m = cls.name_only_regex.search(string)
if m:
return Actor(m.group(1), None)
# Assume the best and use the whole string as name.
return Actor(string, None)
# END special case name
# END handle name/email matching
line = string.partition("\n")[0]
left_bracket = line.find("<")
right_bracket = line.find(">", left_bracket + 1)
if left_bracket >= 0 and right_bracket >= 0:
return Actor(line[:left_bracket].rstrip(), line[left_bracket + 1 : right_bracket])

# Assume the best and use the whole string as name.
return Actor(string, None)

@classmethod
def _main_actor(
Expand Down
20 changes: 20 additions & 0 deletions 20 test/test_actor.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ def test_from_string_should_handle_just_name(self):
self.assertEqual("Michael Trier", a.name)
self.assertEqual(None, a.email)

def test_from_string_handles_unterminated_email_without_regex_backtracking(self):
value = "A" * 20_000 + " <unterminated"
actor = Actor._from_string(value)
self.assertNotIn("name_email_regex", vars(Actor))
self.assertEqual(actor, Actor(value, None))

def test_from_string_does_not_parse_across_lines(self):
self.assertEqual(Actor._from_string("x <a>\n y <b>"), Actor("x", "a"))

def test_from_string_uses_git_delimiters(self):
for value, expected in (
("Name <e<mail>", Actor("Name", "e<mail")),
("Name <email>>", Actor("Name", "email")),
("Name<email>", Actor("Name", "email")),
(" <>", Actor("", "")),
("Name <email", Actor("Name <email", None)),
("Name email>", Actor("Name email>", None)),
):
self.assertEqual(Actor._from_string(value), expected)

def test_should_display_representation(self):
a = Actor._from_string("Michael Trier <[email protected]>")
self.assertEqual('<git.Actor "Michael Trier <[email protected]>">', repr(a))
Expand Down
6 changes: 6 additions & 0 deletions 6 test/test_diff.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from git import NULL_TREE, Diff, DiffIndex, Diffable, GitCommandError, Repo, Submodule
from git.cmd import Git
from git.diff import decode_path
from git.exc import UnsafeOptionError

from test.lib import StringProcessAdapter, TestBase, fixture, with_rw_directory
Expand Down Expand Up @@ -324,6 +325,11 @@ def test_diff_patch_format(self):
Diff._index_from_patch_format(self.rorepo, diff_proc)
# END for each fixture

def test_decode_path_distinguishes_escaped_backslashes_from_octal_bytes(self):
self.assertEqual(decode_path(b'"foo\\\\899bar"', False), b"foo\\899bar")
self.assertEqual(decode_path(b'"foo\\\\123bar"', False), b"foo\\123bar")
self.assertEqual(decode_path(b'"foo\\123bar"', False), b"fooSbar")

def test_diff_with_spaces(self):
data = StringProcessAdapter(fixture("diff_file_with_spaces"))
diff_index = Diff._index_from_patch_format(self.rorepo, data)
Expand Down
Loading
Oops, something went wrong.

Uh oh!

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

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.