Blame SOURCES/00351-cve-2019-20907-fix-infinite-loop-in-tarfile.patch

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