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 — review · gitpython-developers/GitPython@2c9b9a9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • git/objects
    • commit.py
  • test
    • test_commit.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎git/objects/commit.py‎

Copy file name to clipboardExpand all lines: git/objects/commit.py
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,14 +897,16 @@ def _deserialize(self, stream: BytesIO) -> "Commit":
897897
buf = enc.strip()
898898
while buf:
899899
if buf[0:9] == b"encoding ":
900-
encoding = buf[buf.find(b" ") + 1 :].decode(self.encoding, "ignore")
900+
raw_encoding = buf[9:]
901901
try:
902+
# Codec names are ASCII, independent of the content encoding.
903+
encoding = raw_encoding.decode("ascii")
902904
# Probe one byte: decoding b"" skips the codec lookup entirely.
903905
b" ".decode(encoding, "replace")
904906
except (LookupError, ValueError):
905-
# The encoding is not a text encoding Python knows; keep the
906-
# default so the identity and message lines still decode below.
907-
_logger.error("Ignoring unknown commit encoding %r", encoding)
907+
# Reject malformed names and non-text codecs without changing
908+
# the current encoding (the default unless a valid header was read).
909+
_logger.error("Ignoring invalid commit encoding %r", raw_encoding)
908910
else:
909911
self.encoding = encoding
910912
elif buf[0:7] == b"gpgsig ":
Collapse file

‎test/test_commit.py‎

Copy file name to clipboardExpand all lines: test/test_commit.py
+20Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,26 @@ def test_deserialization_unknown_declared_encoding(self):
493493
self.assertEqual(cmt.author.name, "Andr�")
494494
self.assertEqual(cmt.message, "R�sum�\n")
495495

496+
def test_deserialization_multiple_encoding_headers(self):
497+
for headers in (
498+
b"encoding utf-16-be\nencoding ISO-8859-1\n",
499+
b"encoding ISO-8859-1\nencoding utf-\xff8\n",
500+
):
501+
with self.subTest(headers=headers):
502+
data = (
503+
b"tree 3385f7b1e5f91930a3bd3e07105e113fca29981d\n"
504+
b"author Andr\xe9 <[email protected]> 1112591163 +0200\n"
505+
b"committer Andr\xe9 <[email protected]> 1112591163 +0200\n" + headers + b"\n"
506+
b"R\xe9sum\xe9\n"
507+
)
508+
cmt = self.rorepo.commit()
509+
cmt._deserialize(BytesIO(data))
510+
511+
self.assertEqual(cmt.encoding, "ISO-8859-1")
512+
self.assertEqual(cmt.author.name, "André")
513+
self.assertEqual(cmt.committer.name, "André")
514+
self.assertEqual(cmt.message, "Résumé\n")
515+
496516
@with_rw_directory
497517
def test_identity_cannot_alter_headers(self, rw_dir):
498518
"""A name or email must not add header lines or present another identity."""

0 commit comments

Comments
0 (0)
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.