File CVE-2019-20907_tarfile-inf-loop.patch of Package python (Revision 7c7532457b948cc36e86ff51d95885bc)
Currently displaying revision 7c7532457b948cc36e86ff51d95885bc , Show latest
41
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
3 files changed, 7 insertions(+)
11
create mode 100644 Lib/test/recursion.tar
12
13
--- a/Lib/tarfile.py
14
+++ b/Lib/tarfile.py
15
16
17
length, keyword = match.groups()
18
length = int(length)
19
+ if length == 0:
20
+ raise InvalidHeaderError("invalid header")
21
value = buf[match.end(2) + 1:match.start(1) + length - 1]
22
23
keyword = keyword.decode("utf8")
24
--- a/Lib/test/test_tarfile.py
25
+++ b/Lib/test/test_tarfile.py
26
27
with self.assertRaisesRegexp(tarfile.ReadError, "unexpected end of data"):
28
tar.extractfile(t).read()
29
30
+ def test_length_zero_header(self):
31
+ # bpo-39017 (CVE-2019-20907): reading a zero-length header should fail
32
+ # with an exception
33
+ with self.assertRaisesRegexp(tarfile.ReadError, "file could not be opened successfully"):
34
+ with tarfile.open(support.findfile('recursion.tar')) as tar:
35
+ pass
36
+
37
+
38
39
class MiscReadTest(CommonReadTest):
40
taropen = tarfile.TarFile.taropen
41