8000 Merge pull request #3 from ActiveState/jeremyp/cve-20907 · ActiveState/cpython@02daa01 · GitHub
[go: up one dir, main page]

Skip to content

Commit 02daa01

Browse files
authored
Merge pull request #3 from ActiveState/jeremyp/cve-20907
Address CVE-2019-20907 in tarfile module
2 parents d0065ee + e8efbb4 commit 02daa01

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

Lib/tarfile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,8 @@ def _proc_pax(self, tarfile):
14001400

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

14051407
keyword = keyword.decode("utf8")

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
@@ -321,6 +321,13 @@ def test_premature_end_of_archive(self):
321321
with self.assertRaisesRegexp(tarfile.ReadError, "unexpected end of data"):
322322
tar.extractfile(t).read()
323323

324+
def test_length_zero_header(self):
325+
# bpo-39017 (CVE-2019-20907): reading a zero-length header should fail
326+
# with an exception
327+
with self.assertRaisesRegexp(tarfile.ReadError, "file could not be opened successfully"):
328+
with tarfile.open(support.findfile('recursion.tar')) as tar:
329+
pass
330+
324331

325332
class MiscReadTest(CommonReadTest):
326333
taropen = tarfile.TarFile.taropen

0 commit comments

Comments
 (0)
0