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