Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 75ff65e

Browse files
committed
Issue #13806: The size check in audioop decompression functions was too strict and could reject valid compressed data.
Patch by Oleg Plakhotnyuk.
1 parent eba63c4 commit 75ff65e

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

Lib/test/test_audioop.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ def gendata4():
2121
data = [gendata1(), gendata2(), gendata4()]
2222

2323
INVALID_DATA = [
24-
('abc', 0),
25-
('abc', 2),
26-
('abc', 4),
24+
(b'abc', 0),
25+
(b'abc', 2),
26+
(b'abc', 4),
2727
]
2828

2929

@@ -94,7 +94,9 @@ def test_lin2lin(self):
9494

9595
def test_adpcm2lin(self):
9696
# Very cursory test
97-
self.assertEqual(audioop.adpcm2lin(b'\0\0', 1, None), (b'\0\0\0\0', (0,0)))
97+
self.assertEqual(audioop.adpcm2lin(b'\0\0', 1, None), (b'\0' * 4, (0,0)))
98+
self.assertEqual(audioop.adpcm2lin(b'\0\0', 2, None), (b'\0' * 8, (0,0)))
99+
self.assertEqual(audioop.adpcm2lin(b'\0\0', 4, None), (b'\0' * 16, (0,0)))
98100

99101
def test_lin2adpcm(self):
100102
# Very cursory test
@@ -109,6 +111,9 @@ def test_alaw2lin(self):
109111
# Cursory
110112
d = audioop.lin2alaw(data[0], 1)
111113
self.assertEqual(audioop.alaw2lin(d, 1), data[0])
114+
self.assertEqual(audioop.alaw2lin(d, 2), b'\x08\x00\x08\x01\x10\x02')
115+
self.assertEqual(audioop.alaw2lin(d, 4),
116+
b'\x00\x00\x08\x00\x00\x00\x08\x01\x00\x00\x10\x02')
112117

113118
def test_lin2ulaw(self):
114119
self.assertEqual(audioop.lin2ulaw(data[0], 1), b'\xff\xe7\xdb')
@@ -119,6 +124,9 @@ def test_ulaw2lin(self):
119124
# Cursory
120125
d = audioop.lin2ulaw(data[0], 1)
121126
self.assertEqual(audioop.ulaw2lin(d, 1), data[0])
127+
self.assertEqual(audioop.ulaw2lin(d, 2), b'\x00\x00\x04\x01\x0c\x02')
128+
self.assertEqual(audioop.ulaw2lin(d, 4),
129+
b'\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x0c\x02')
122130

123131
def test_mul(self):
124132
data2 = []
@@ -195,10 +203,15 @@ def test_issue7673(self):
195203
self.assertRaises(audioop.error, audioop.lin2lin, data, size, size2)
196204
self.assertRaises(audioop.error, audioop.ratecv, data, size, 1, 1, 1, state)
197205
self.assertRaises(audioop.error, audioop.lin2ulaw, data, size)
198-
self.assertRaises(audioop.error, audioop.ulaw2lin, data, size)
199206
self.assertRaises(audioop.error, audioop.lin2alaw, data, size)
200-
self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
201207
self.assertRaises(audioop.error, audioop.lin2adpcm, data, size, state)
208+
209+
def test_wrongsize(self):
210+
data = b'abc'
211+
state = None
212+
for size in (-1, 3, 5):
213+
self.assertRaises(audioop.error, audioop.ulaw2lin, data, size)
214+
self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
202215
self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, state)
203216

204217
def test_main():

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ Core and Builtins
111111
Library
112112
-------
113113

114+
- Issue #13806: The size check in audioop decompression functions was too
115+
strict and could reject valid compressed data. Patch by Oleg Plakhotnyuk.
116+
114117
- Issue #13812: When a multiprocessing Process child raises an exception,
115118
flush stderr after printing the exception traceback.
116119

Modules/audioop.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ audioop_ulaw2lin(PyObject *self, PyObject *args)
13131313
&cp, &len, &size) )
13141314
return 0;
13151315

1316-
if (!audioop_check_parameters(len, size))
1316+
if (!audioop_check_size(size))
13171317
return NULL;
13181318

13191319
if (len > PY_SSIZE_T_MAX/size) {
@@ -1382,7 +1382,7 @@ audioop_alaw2lin(PyObject *self, PyObject *args)
13821382
&cp, &len, &size) )
13831383
return 0;
13841384

1385-
if (!audioop_check_parameters(len, size))
1385+
if (!audioop_check_size(size))
13861386
return NULL;
13871387

13881388
if (len > PY_SSIZE_T_MAX/size) {
@@ -1527,7 +1527,7 @@ audioop_adpcm2lin(PyObject *self, PyObject *args)
15271527
&cp, &len, &size, &state) )
15281528
return 0;
15291529

1530-
if (!audioop_check_parameters(len, size))
1530+
if (!audioop_check_size(size))
15311531
return NULL;
15321532

15331533
/* Decode state, should have (value, step) */

0 commit comments

Comments
 (0)