Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 2 Lib/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,8 @@ def _proc_pax(self, tarfile):

length, keyword = match.groups()
length = int(length)
if length == 0:
raise InvalidHeaderError("invalid header")
value = buf[match.end(2) + 1:match.start(1) + length - 1]

# Normally, we could just use "utf-8" as the encoding and "strict"
Expand Down
Binary file added BIN +516 Bytes Lib/test/recursion.tar
Binary file not shown.
7 changes: 7 additions & 0 deletions 7 Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,13 @@ def test_premature_end_of_archive(self):
with self.assertRaisesRegex(tarfile.ReadError, "unexpected end of data"):
tar.extractfile(t).read()

def test_length_zero_header(self):
# bpo-39017 (CVE-2019-20907): reading a zero-length header should fail
# with an exception
with self.assertRaisesRegex(tarfile.ReadError, "file could not be opened successfully"):
with tarfile.open(support.findfile('recursion.tar')) as tar:
pass

class MiscReadTestBase(CommonReadTest):
def requires_name_attribute(self):
pass
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid infinite loop when reading specially crafted TAR files using the tarfile module (CVE-2019-20907).
Morty Proxy This is a proxified and sanitized view of the page, visit original site.