|
|
556498 |
From b099ce737f6e6cc9f3a1bf756af78eaa1c1480cd Mon Sep 17 00:00:00 2001
|
|
|
556498 |
From: Rishi <rishi_devan@mail.com>
|
|
|
556498 |
Date: Wed, 15 Jul 2020 13:51:00 +0200
|
|
|
556498 |
Subject: [PATCH] 00351-cve-2019-20907-fix-infinite-loop-in-tarfile.patch
|
|
|
556498 |
|
|
|
556498 |
00351 #
|
|
|
556498 |
Avoid infinite loop when reading specially crafted TAR files using the tarfile module
|
|
|
556498 |
(CVE-2019-20907).
|
|
|
556498 |
See: https://bugs.python.org/issue39017
|
|
|
556498 |
---
|
|
|
556498 |
Lib/tarfile.py | 2 ++
|
|
|
556498 |
Lib/test/recursion.tar | Bin 0 -> 516 bytes
|
|
|
556498 |
Lib/test/test_tarfile.py | 7 +++++++
|
|
|
556498 |
.../2020-07-12-22-16-58.bpo-39017.x3Cg-9.rst | 1 +
|
|
|
556498 |
4 files changed, 10 insertions(+)
|
|
|
556498 |
create mode 100644 Lib/test/recursion.tar
|
|
|
556498 |
create mode 100644 Misc/NEWS.d/next/Library/2020-07-12-22-16-58.bpo-39017.x3Cg-9.rst
|
|
|
556498 |
|
|
|
556498 |
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
|
|
|
556498 |
index adf91d5..574a6bb 100644
|
|
|
556498 |
--- a/Lib/tarfile.py
|
|
|
556498 |
+++ b/Lib/tarfile.py
|
|
|
556498 |
@@ -1400,6 +1400,8 @@ class TarInfo(object):
|
|
|
556498 |
|
|
|
556498 |
length, keyword = match.groups()
|
|
|
556498 |
length = int(length)
|
|
|
556498 |
+ if length == 0:
|
|
|
556498 |
+ raise InvalidHeaderError("invalid header")
|
|
|
556498 |
value = buf[match.end(2) + 1:match.start(1) + length - 1]
|
|
|
556498 |
|
|
|
556498 |
keyword = keyword.decode("utf8")
|
|
|
556498 |
diff --git a/Lib/test/recursion.tar b/Lib/test/recursion.tar
|
|
|
556498 |
new file mode 100644
|
|
|
556498 |
index 0000000000000000000000000000000000000000..b8237251964983f54ed1966297e887636cd0c5f4
|
|
|
556498 |
GIT binary patch
|
|
|
556498 |
literal 516
|
|
|
556498 |
zcmYdFPRz+kEn=W0Fn}74P8%Xw3X=l~85kIuo0>8xq$A1Gm}!7)KUsFc41m#O8A5+e
|
|
|
556498 |
I1_}|j06>QaCIA2c
|
|
|
556498 |
|
|
|
556498 |
literal 0
|
|
|
556498 |
HcmV?d00001
|
|
|
556498 |
|
|
|
556498 |
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
|
|
|
556498 |
index 89bd738..4592156 100644
|
|
|
556498 |
--- a/Lib/test/test_tarfile.py
|
|
|
556498 |
+++ b/Lib/test/test_tarfile.py
|
|
|
556498 |
@@ -325,6 +325,13 @@ class CommonReadTest(ReadTest):
|
|
|
556498 |
class MiscReadTest(CommonReadTest):
|
|
|
556498 |
taropen = tarfile.TarFile.taropen
|
|
|
556498 |
|
|
|
556498 |
+ def test_length_zero_header(self):
|
|
|
556498 |
+ # bpo-39017 (CVE-2019-20907): reading a zero-length header should fail
|
|
|
556498 |
+ # with an exception
|
|
|
556498 |
+ with self.assertRaisesRegexp(tarfile.ReadError, "file could not be opened successfully"):
|
|
|
556498 |
+ with tarfile.open(support.findfile('recursion.tar')) as tar:
|
|
|
556498 |
+ pass
|
|
|
556498 |
+
|
|
|
556498 |
def test_no_name_argument(self):
|
|
|
556498 |
with open(self.tarname, "rb") as fobj:
|
|
|
556498 |
tar = tarfile.open(fileobj=fobj, mode=self.mode)
|
|
|
556498 |
diff --git a/Misc/NEWS.d/next/Library/2020-07-12-22-16-58.bpo-39017.x3Cg-9.rst b/Misc/NEWS.d/next/Library/2020-07-12-22-16-58.bpo-39017.x3Cg-9.rst
|
|
|
556498 |
new file mode 100644
|
|
|
556498 |
index 0000000..ad26676
|
|
|
556498 |
--- /dev/null
|
|
|
556498 |
+++ b/Misc/NEWS.d/next/Library/2020-07-12-22-16-58.bpo-39017.x3Cg-9.rst
|
|
|
556498 |
@@ -0,0 +1 @@
|
|
|
556498 |
+Avoid infinite loop when reading specially crafted TAR files using the tarfile module (CVE-2019-20907).
|
|
|
556498 |
--
|
|
|
556498 |
2.25.4
|
|
|
556498 |
|