File CVE-2019-20907_tarfile-inf-loop.patch of Package python (Revision 45c655118baafa05bf3b932915819c13)
Currently displaying revision 45c655118baafa05bf3b932915819c13 , Show latest
43
1
From 1fa6ef2bc7cee1c8e088dd8b397d9b2d54036dbc Mon Sep 17 00:00:00 2001
2
From: Rajarishi Devarajan <rishi93dev@gmail.com>
3
Date: Sun, 12 Jul 2020 23:47:42 +0200
4
Subject: [PATCH 1/4] bpo-39017 Fix infinite loop in the tarfile module
5
6
Add a check for length = 0 in the _proc_pax function to avoid running into an infinite loop
7
---
8
Lib/tarfile.py | 2 ++
9
Lib/test/test_tarfile.py | 5 +++++
10
Misc/NEWS.d/next/Library/2020-07-12-22-16-58.bpo-39017.x3Cg-9.rst | 1 +
11
3 files changed, 8 insertions(+)
12
create mode 100644 Lib/test/recursion.tar
13
14
--- a/Lib/tarfile.py
15
+++ b/Lib/tarfile.py
16
17
18
length, keyword = match.groups()
19
length = int(length)
20
+ if length == 0:
21
+ raise InvalidHeaderError("invalid header")
22
value = buf[match.end(2) + 1:match.start(1) + length - 1]
23
24
keyword = keyword.decode("utf8")
25
--- a/Lib/test/test_tarfile.py
26
+++ b/Lib/test/test_tarfile.py
27
28
with self.assertRaisesRegexp(tarfile.ReadError, "unexpected end of data"):
29
tar.extractfile(t).read()
30
31
+ def test_length_zero_header(self):
32
+ # bpo-39017 (CVE-2019-20907): reading a zero-length header should fail
33
+ # with an exception
34
+ self.assertRaises(tarfile.ReadError, tarfile.open, test_support.findfile('recursion.tar'))
35
+
36
37
class MiscReadTest(CommonReadTest):
38
taropen = tarfile.TarFile.taropen
39
--- /dev/null
40
+++ b/Misc/NEWS.d/next/Library/2020-07-12-22-16-58.bpo-39017.x3Cg-9.rst
41
42
+Avoid infinite loop when reading specially crafted TAR files using the tarfile module (CVE-2019-20907).
43