Browse code

python3 : Update to version 3.6.5 to fix CVE-2018-1000117, Apply patch for CVE-2017-18207

Change-Id: I1a413691ff905d02983d470de62314d1980e2e84
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/5041
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Anish Swaminathan <anishs@vmware.com>

Xiaolin Li authored on 2018/04/20 08:46:26
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,288 @@
0
+From 134cb01cda50f02725575808130b05d2d776693f Mon Sep 17 00:00:00 2001
1
+From: Serhiy Storchaka <storchaka@gmail.com>
2
+Date: Sun, 18 Mar 2018 09:55:53 +0200
3
+Subject: [PATCH] bpo-32056: Improve exceptions in aifc, wave and sunau.
4
+ (GH-5951)
5
+
6
+---
7
+ Lib/aifc.py                                        |  4 ++
8
+ Lib/sunau.py                                       |  2 +
9
+ Lib/test/test_aifc.py                              | 35 ++++++++++--
10
+ Lib/test/test_sunau.py                             | 37 +++++++++++++
11
+ Lib/test/test_wave.py                              | 62 ++++++++++++++++++++++
12
+ Lib/wave.py                                        | 14 ++++-
13
+ .../2018-03-01-17-49-56.bpo-32056.IlpfgE.rst       |  3 ++
14
+ 7 files changed, 150 insertions(+), 7 deletions(-)
15
+ create mode 100644 Misc/NEWS.d/next/Library/2018-03-01-17-49-56.bpo-32056.IlpfgE.rst
16
+
17
+diff --git a/Lib/aifc.py b/Lib/aifc.py
18
+index 3d2dc56de198..1916e7ef8e7e 100644
19
+--- a/Lib/aifc.py
20
+@@ -467,6 +467,10 @@ def _read_comm_chunk(self, chunk):
21
+         self._nframes = _read_long(chunk)
22
+         self._sampwidth = (_read_short(chunk) + 7) // 8
23
+         self._framerate = int(_read_float(chunk))
24
++        if self._sampwidth <= 0:
25
++            raise Error('bad sample width')
26
++        if self._nchannels <= 0:
27
++            raise Error('bad # of channels')
28
+         self._framesize = self._nchannels * self._sampwidth
29
+         if self._aifc:
30
+             #DEBUG: SGI's soundeditor produces a bad size :-(
31
+diff --git a/Lib/sunau.py b/Lib/sunau.py
32
+index dbad3db8392d..129502b0b417 100644
33
+--- a/Lib/sunau.py
34
+@@ -208,6 +208,8 @@ def initfp(self, file):
35
+             raise Error('unknown encoding')
36
+         self._framerate = int(_read_u32(file))
37
+         self._nchannels = int(_read_u32(file))
38
++        if not self._nchannels:
39
++            raise Error('bad # of channels')
40
+         self._framesize = self._framesize * self._nchannels
41
+         if self._hdr_size > 24:
42
+             self._info = file.read(self._hdr_size - 24)
43
+diff --git a/Lib/test/test_aifc.py b/Lib/test/test_aifc.py
44
+index 8fd306a36592..ff52f5b6feb8 100644
45
+--- a/Lib/test/test_aifc.py
46
+@@ -268,7 +268,8 @@ def test_read_no_comm_chunk(self):
47
+ 
48
+     def test_read_no_ssnd_chunk(self):
49
+         b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
50
+-        b += b'COMM' + struct.pack('>LhlhhLL', 38, 0, 0, 0, 0, 0, 0)
51
++        b += b'COMM' + struct.pack('>LhlhhLL', 38, 1, 0, 8,
52
++                                   0x4000 | 12, 11025<<18, 0)
53
+         b += b'NONE' + struct.pack('B', 14) + b'not compressed' + b'\x00'
54
+         with self.assertRaisesRegex(aifc.Error, 'COMM chunk and/or SSND chunk'
55
+                                                 ' missing'):
56
+@@ -276,13 +277,35 @@ def test_read_no_ssnd_chunk(self):
57
+ 
58
+     def test_read_wrong_compression_type(self):
59
+         b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
60
+-        b += b'COMM' + struct.pack('>LhlhhLL', 23, 0, 0, 0, 0, 0, 0)
61
++        b += b'COMM' + struct.pack('>LhlhhLL', 23, 1, 0, 8,
62
++                                   0x4000 | 12, 11025<<18, 0)
63
+         b += b'WRNG' + struct.pack('B', 0)
64
+         self.assertRaises(aifc.Error, aifc.open, io.BytesIO(b))
65
+ 
66
++    def test_read_wrong_number_of_channels(self):
67
++        for nchannels in 0, -1:
68
++            b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
69
++            b += b'COMM' + struct.pack('>LhlhhLL', 38, nchannels, 0, 8,
70
++                                       0x4000 | 12, 11025<<18, 0)
71
++            b += b'NONE' + struct.pack('B', 14) + b'not compressed' + b'\x00'
72
++            b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8
73
++            with self.assertRaisesRegex(aifc.Error, 'bad # of channels'):
74
++                aifc.open(io.BytesIO(b))
75
++
76
++    def test_read_wrong_sample_width(self):
77
++        for sampwidth in 0, -1:
78
++            b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
79
++            b += b'COMM' + struct.pack('>LhlhhLL', 38, 1, 0, sampwidth,
80
++                                       0x4000 | 12, 11025<<18, 0)
81
++            b += b'NONE' + struct.pack('B', 14) + b'not compressed' + b'\x00'
82
++            b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8
83
++            with self.assertRaisesRegex(aifc.Error, 'bad sample width'):
84
++                aifc.open(io.BytesIO(b))
85
++
86
+     def test_read_wrong_marks(self):
87
+         b = b'FORM' + struct.pack('>L', 4) + b'AIFF'
88
+-        b += b'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0)
89
++        b += b'COMM' + struct.pack('>LhlhhLL', 18, 1, 0, 8,
90
++                                   0x4000 | 12, 11025<<18, 0)
91
+         b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8
92
+         b += b'MARK' + struct.pack('>LhB', 3, 1, 1)
93
+         with self.assertWarns(UserWarning) as cm:
94
+@@ -293,7 +316,8 @@ def test_read_wrong_marks(self):
95
+ 
96
+     def test_read_comm_kludge_compname_even(self):
97
+         b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
98
+-        b += b'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0)
99
++        b += b'COMM' + struct.pack('>LhlhhLL', 18, 1, 0, 8,
100
++                                   0x4000 | 12, 11025<<18, 0)
101
+         b += b'NONE' + struct.pack('B', 4) + b'even' + b'\x00'
102
+         b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8
103
+         with self.assertWarns(UserWarning) as cm:
104
+@@ -303,7 +327,8 @@ def test_read_comm_kludge_compname_even(self):
105
+ 
106
+     def test_read_comm_kludge_compname_odd(self):
107
+         b = b'FORM' + struct.pack('>L', 4) + b'AIFC'
108
+-        b += b'COMM' + struct.pack('>LhlhhLL', 18, 0, 0, 0, 0, 0, 0)
109
++        b += b'COMM' + struct.pack('>LhlhhLL', 18, 1, 0, 8,
110
++                                   0x4000 | 12, 11025<<18, 0)
111
+         b += b'NONE' + struct.pack('B', 3) + b'odd'
112
+         b += b'SSND' + struct.pack('>L', 8) + b'\x00' * 8
113
+         with self.assertWarns(UserWarning) as cm:
114
+diff --git a/Lib/test/test_sunau.py b/Lib/test/test_sunau.py
115
+index 966224b1df5a..470a1007b4d4 100644
116
+--- a/Lib/test/test_sunau.py
117
+@@ -1,6 +1,8 @@
118
+ import unittest
119
+ from test import audiotests
120
+ from audioop import byteswap
121
++import io
122
++import struct
123
+ import sys
124
+ import sunau
125
+ 
126
+@@ -121,5 +123,40 @@ class SunauMiscTests(audiotests.AudioMiscTests, unittest.TestCase):
127
+     module = sunau
128
+ 
129
+ 
130
++class SunauLowLevelTest(unittest.TestCase):
131
++
132
++    def test_read_bad_magic_number(self):
133
++        b = b'SPA'
134
++        with self.assertRaises(EOFError):
135
++            sunau.open(io.BytesIO(b))
136
++        b = b'SPAM'
137
++        with self.assertRaisesRegex(sunau.Error, 'bad magic number'):
138
++            sunau.open(io.BytesIO(b))
139
++
140
++    def test_read_too_small_header(self):
141
++        b = struct.pack('>LLLLL', sunau.AUDIO_FILE_MAGIC, 20, 0,
142
++                        sunau.AUDIO_FILE_ENCODING_LINEAR_8, 11025)
143
++        with self.assertRaisesRegex(sunau.Error, 'header size too small'):
144
++            sunau.open(io.BytesIO(b))
145
++
146
++    def test_read_too_large_header(self):
147
++        b = struct.pack('>LLLLLL', sunau.AUDIO_FILE_MAGIC, 124, 0,
148
++                        sunau.AUDIO_FILE_ENCODING_LINEAR_8, 11025, 1)
149
++        b += b'\0' * 100
150
++        with self.assertRaisesRegex(sunau.Error, 'header size ridiculously large'):
151
++            sunau.open(io.BytesIO(b))
152
++
153
++    def test_read_wrong_encoding(self):
154
++        b = struct.pack('>LLLLLL', sunau.AUDIO_FILE_MAGIC, 24, 0, 0, 11025, 1)
155
++        with self.assertRaisesRegex(sunau.Error, r'encoding not \(yet\) supported'):
156
++            sunau.open(io.BytesIO(b))
157
++
158
++    def test_read_wrong_number_of_channels(self):
159
++        b = struct.pack('>LLLLLL', sunau.AUDIO_FILE_MAGIC, 24, 0,
160
++                        sunau.AUDIO_FILE_ENCODING_LINEAR_8, 11025, 0)
161
++        with self.assertRaisesRegex(sunau.Error, 'bad # of channels'):
162
++            sunau.open(io.BytesIO(b))
163
++
164
++
165
+ if __name__ == "__main__":
166
+     unittest.main()
167
+diff --git a/Lib/test/test_wave.py b/Lib/test/test_wave.py
168
+index c5d2e02450ef..8a42f8e47105 100644
169
+--- a/Lib/test/test_wave.py
170
+@@ -2,6 +2,8 @@
171
+ from test import audiotests
172
+ from test import support
173
+ from audioop import byteswap
174
++import io
175
++import struct
176
+ import sys
177
+ import wave
178
+ 
179
+@@ -111,5 +113,65 @@ def test__all__(self):
180
+         support.check__all__(self, wave, blacklist=blacklist)
181
+ 
182
+ 
183
++class WaveLowLevelTest(unittest.TestCase):
184
++
185
++    def test_read_no_chunks(self):
186
++        b = b'SPAM'
187
++        with self.assertRaises(EOFError):
188
++            wave.open(io.BytesIO(b))
189
++
190
++    def test_read_no_riff_chunk(self):
191
++        b = b'SPAM' + struct.pack('<L', 0)
192
++        with self.assertRaisesRegex(wave.Error,
193
++                                    'file does not start with RIFF id'):
194
++            wave.open(io.BytesIO(b))
195
++
196
++    def test_read_not_wave(self):
197
++        b = b'RIFF' + struct.pack('<L', 4) + b'SPAM'
198
++        with self.assertRaisesRegex(wave.Error,
199
++                                    'not a WAVE file'):
200
++            wave.open(io.BytesIO(b))
201
++
202
++    def test_read_no_fmt_no_data_chunk(self):
203
++        b = b'RIFF' + struct.pack('<L', 4) + b'WAVE'
204
++        with self.assertRaisesRegex(wave.Error,
205
++                                    'fmt chunk and/or data chunk missing'):
206
++            wave.open(io.BytesIO(b))
207
++
208
++    def test_read_no_data_chunk(self):
209
++        b = b'RIFF' + struct.pack('<L', 28) + b'WAVE'
210
++        b += b'fmt ' + struct.pack('<LHHLLHH', 16, 1, 1, 11025, 11025, 1, 8)
211
++        with self.assertRaisesRegex(wave.Error,
212
++                                    'fmt chunk and/or data chunk missing'):
213
++            wave.open(io.BytesIO(b))
214
++
215
++    def test_read_no_fmt_chunk(self):
216
++        b = b'RIFF' + struct.pack('<L', 12) + b'WAVE'
217
++        b += b'data' + struct.pack('<L', 0)
218
++        with self.assertRaisesRegex(wave.Error, 'data chunk before fmt chunk'):
219
++            wave.open(io.BytesIO(b))
220
++
221
++    def test_read_wrong_form(self):
222
++        b = b'RIFF' + struct.pack('<L', 36) + b'WAVE'
223
++        b += b'fmt ' + struct.pack('<LHHLLHH', 16, 2, 1, 11025, 11025, 1, 1)
224
++        b += b'data' + struct.pack('<L', 0)
225
++        with self.assertRaisesRegex(wave.Error, 'unknown format: 2'):
226
++            wave.open(io.BytesIO(b))
227
++
228
++    def test_read_wrong_number_of_channels(self):
229
++        b = b'RIFF' + struct.pack('<L', 36) + b'WAVE'
230
++        b += b'fmt ' + struct.pack('<LHHLLHH', 16, 1, 0, 11025, 11025, 1, 8)
231
++        b += b'data' + struct.pack('<L', 0)
232
++        with self.assertRaisesRegex(wave.Error, 'bad # of channels'):
233
++            wave.open(io.BytesIO(b))
234
++
235
++    def test_read_wrong_sample_width(self):
236
++        b = b'RIFF' + struct.pack('<L', 36) + b'WAVE'
237
++        b += b'fmt ' + struct.pack('<LHHLLHH', 16, 1, 1, 11025, 11025, 1, 0)
238
++        b += b'data' + struct.pack('<L', 0)
239
++        with self.assertRaisesRegex(wave.Error, 'bad sample width'):
240
++            wave.open(io.BytesIO(b))
241
++
242
++
243
+ if __name__ == '__main__':
244
+     unittest.main()
245
+diff --git a/Lib/wave.py b/Lib/wave.py
246
+index cf94d5af72b4..f155879a9a76 100644
247
+--- a/Lib/wave.py
248
+@@ -253,12 +253,22 @@ def readframes(self, nframes):
249
+     #
250
+ 
251
+     def _read_fmt_chunk(self, chunk):
252
+-        wFormatTag, self._nchannels, self._framerate, dwAvgBytesPerSec, wBlockAlign = struct.unpack_from('<HHLLH', chunk.read(14))
253
++        try:
254
++            wFormatTag, self._nchannels, self._framerate, dwAvgBytesPerSec, wBlockAlign = struct.unpack_from('<HHLLH', chunk.read(14))
255
++        except struct.error:
256
++            raise EOFError from None
257
+         if wFormatTag == WAVE_FORMAT_PCM:
258
+-            sampwidth = struct.unpack_from('<H', chunk.read(2))[0]
259
++            try:
260
++                sampwidth = struct.unpack_from('<H', chunk.read(2))[0]
261
++            except struct.error:
262
++                raise EOFError from None
263
+             self._sampwidth = (sampwidth + 7) // 8
264
++            if not self._sampwidth:
265
++                raise Error('bad sample width')
266
+         else:
267
+             raise Error('unknown format: %r' % (wFormatTag,))
268
++        if not self._nchannels:
269
++            raise Error('bad # of channels')
270
+         self._framesize = self._nchannels * self._sampwidth
271
+         self._comptype = 'NONE'
272
+         self._compname = 'not compressed'
273
+diff --git a/Misc/NEWS.d/next/Library/2018-03-01-17-49-56.bpo-32056.IlpfgE.rst b/Misc/NEWS.d/next/Library/2018-03-01-17-49-56.bpo-32056.IlpfgE.rst
274
+new file mode 100644
275
+index 000000000000..421aa3767794
276
+--- /dev/null
277
+@@ -0,0 +1,3 @@
278
++Improved exceptions raised for invalid number of channels and sample width
279
++when read an audio file in modules :mod:`aifc`, :mod:`wave` and
280
++:mod:`sunau`.
... ...
@@ -1,18 +1,17 @@
1 1
 Summary:        A high-level scripting language
2 2
 Name:           python3
3
-Version:        3.6.1
4
-Release:        9%{?dist}
3
+Version:        3.6.5
4
+Release:        1%{?dist}
5 5
 License:        PSF
6 6
 URL:            http://www.python.org/
7 7
 Group:          System Environment/Programming
8 8
 Vendor:         VMware, Inc.
9 9
 Distribution:   Photon
10 10
 Source0:        https://www.python.org/ftp/python/%{version}/Python-%{version}.tar.xz
11
-%define sha1    Python=91d880a2a9fcfc6753cbfa132bf47a47e17e7b16
11
+%define sha1    Python=5a7a833a36f1006257d298787f4c38493c5d1689
12 12
 Patch0:         cgi3.patch
13 13
 Patch1:         python3-support-photon-platform.patch
14
-#https://github.com/python/cpython/pull/1320/commits/a252330d53afad6f8a4645933989bb017dc35ad8
15
-Patch2:         skip-imaplib-test.patch
14
+Patch2:         python3-CVE-2017-18207.patch
16 15
 BuildRequires:  pkg-config >= 0.28
17 16
 BuildRequires:  bzip2-devel
18 17
 BuildRequires:  ncurses-devel
... ...
@@ -134,7 +133,7 @@ The test package contains all regression tests for Python as well as the modules
134 134
 %setup -q -n Python-%{version}
135 135
 %patch0 -p1
136 136
 %patch1 -p1
137
-%patch2 -p1
137
+#%patch2 -p1
138 138
 
139 139
 %build
140 140
 export OPT="${CFLAGS}"
... ...
@@ -200,7 +199,7 @@ rm -rf %{buildroot}/*
200 200
 %files libs
201 201
 %defattr(-,root,root)
202 202
 %doc LICENSE README.rst
203
-%{_libdir}/python3.6
203
+%{_libdir}/python3.6/*
204 204
 %{_libdir}/python3.6/site-packages/easy_install.py
205 205
 %{_libdir}/python3.6/site-packages/README.txt
206 206
 %exclude %{_libdir}/python3.6/site-packages/
... ...
@@ -249,20 +248,23 @@ rm -rf %{buildroot}/*
249 249
 %files pip
250 250
 %defattr(-,root,root,755)
251 251
 %{_libdir}/python3.6/site-packages/pip/*
252
-%{_libdir}/python3.6/site-packages/pip-9.0.1.dist-info/*
252
+%{_libdir}/python3.6/site-packages/pip-9.0.3.dist-info/*
253 253
 %{_bindir}/pip*
254 254
 
255 255
 %files setuptools
256 256
 %defattr(-,root,root,755)
257 257
 %{_libdir}/python3.6/site-packages/pkg_resources/*
258 258
 %{_libdir}/python3.6/site-packages/setuptools/*
259
-%{_libdir}/python3.6/site-packages/setuptools-28.8.0.dist-info/*
259
+%{_libdir}/python3.6/site-packages/setuptools-39.0.1.dist-info/*
260 260
 %{_bindir}/easy_install-3.6
261 261
 
262 262
 %files test
263 263
 %{_libdir}/python3.6/test/*
264 264
 
265 265
 %changelog
266
+*   Thu Apr 19 2018 Xiaolin Li <xiaolinl@vmware.com> 3.6.5-1
267
+-   Update to version 3.6.5 to fix CVE-2018-1000117
268
+-   Apply patch for CVE-2017-18207
266 269
 *   Mon Sep 18 2017 Alexey Makhalov <amakhalov@vmware.com> 3.6.1-9
267 270
 -   Requires coreutils or toybox
268 271
 -   Requires bzip2-libs