Skip to content

Commit e46bdda

Browse files
authored
Merge pull request #9827 from pradyunsg/fix-git-improper-tag-handling
Don't split git references on unicode separators
2 parents 1320bac + 0e4938d commit e46bdda

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Diff for: news/9827.bugfix.rst

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
**SECURITY**: Stop splitting on unicode separators in git references,
2+
which could be maliciously used to install a different revision on the
3+
repository.

Diff for: src/pip/_internal/vcs/git.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,15 @@ def get_revision_sha(cls, dest, rev):
131131
on_returncode='ignore',
132132
)
133133
refs = {}
134-
for line in output.strip().splitlines():
134+
# NOTE: We do not use splitlines here since that would split on other
135+
# unicode separators, which can be maliciously used to install a
136+
# different revision.
137+
for line in output.strip().split("\n"):
138+
line = line.rstrip("\r")
139+
if not line:
140+
continue
135141
try:
136-
ref_sha, ref_name = line.split()
142+
ref_sha, ref_name = line.split(" ", maxsplit=2)
137143
except ValueError:
138144
# Include the offending line to simplify troubleshooting if
139145
# this error ever occurs.

0 commit comments

Comments
 (0)