8000 [3.6] bpo-39017: Avoid infinite loop in the tarfile module (GH-21454) by miss-islington · Pull Request #21485 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.6] 8000 bpo-39017: Avoid infinite loop in the tarfile module (GH-21454) #21485

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.

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
merged 1 commit into from
Jul 15, 2020
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 Lib/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,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 Lib/test/recursion.tar
Binary file not shown.
7 changes: 7 additions & 0 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,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).
0