bpo-39017: Avoid infinite loop in the tarfile module (GH-21454) · python/cpython@5a8d121 · GitHub
Skip to content

Commit 5a8d121

Browse files
authored
bpo-39017: Avoid infinite loop in the tarfile module (GH-21454)
Avoid infinite loop when reading specially crafted TAR files using the tarfile module (CVE-2019-20907).
1 parent bbceef6 commit 5a8d121

4 files changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/tarfile.py

Lines changed: 2 additions & 0 deletions

Lib/test/recursion.tar

516 Bytes
Binary file not shown.

Lib/test/test_tarfile.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,13 @@ def test_premature_end_of_archive(self):
429429
with self.assertRaisesRegex(tarfile.ReadError, "unexpected end of data"):
430430
tar.extractfile(t).read()
431431

432+
def test_length_zero_header(self):
433+
# bpo-39017 (CVE-2019-20907): reading a zero-length header should fail
434+
# with an exception
435+
with self.assertRaisesRegex(tarfile.ReadError, "file could not be opened successfully"):
436+
with tarfile.open(support.findfile('recursion.tar')) as tar:
437+
pass
438+
432439
class MiscReadTestBase(CommonReadTest):
433440
def requires_name_attribute(self):
434441
pass
Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)