[Python-checkins] cpython (merge 3.2 -> default): Issue #13806: The size check in audioop decompression functions was too strict

antoine.pitrou python-checkins at python.org
Sat Jan 28 22:07:34 CET 2012


http://hg.python.org/cpython/rev/ce89dcba008f
changeset: 74671:ce89dcba008f
parent: 74669:db0c717cbc01
parent: 74670:77188bc37c74
user: Antoine Pitrou <solipsis at pitrou.net>
date: Sat Jan 28 22:02:47 2012 +0100
summary:
 Issue #13806: The size check in audioop decompression functions was too strict and could reject valid compressed data.
Patch by Oleg Plakhotnyuk.
files:
 Lib/test/test_audioop.py | 25 +++++++++++++++++++------
 Misc/NEWS | 3 +++
 Modules/audioop.c | 6 +++---
 3 files changed, 25 insertions(+), 9 deletions(-)
diff --git a/Lib/test/test_audioop.py b/Lib/test/test_audioop.py
--- a/Lib/test/test_audioop.py
+++ b/Lib/test/test_audioop.py
@@ -21,9 +21,9 @@
 data = [gendata1(), gendata2(), gendata4()]
 
 INVALID_DATA = [
- ('abc', 0),
- ('abc', 2),
- ('abc', 4),
+ (b'abc', 0),
+ (b'abc', 2),
+ (b'abc', 4),
 ]
 
 
@@ -94,7 +94,9 @@
 
 def test_adpcm2lin(self):
 # Very cursory test
- self.assertEqual(audioop.adpcm2lin(b'0円0円', 1, None), (b'0円0円0円0円', (0,0)))
+ self.assertEqual(audioop.adpcm2lin(b'0円0円', 1, None), (b'0円' * 4, (0,0)))
+ self.assertEqual(audioop.adpcm2lin(b'0円0円', 2, None), (b'0円' * 8, (0,0)))
+ self.assertEqual(audioop.adpcm2lin(b'0円0円', 4, None), (b'0円' * 16, (0,0)))
 
 def test_lin2adpcm(self):
 # Very cursory test
@@ -109,6 +111,9 @@
 # Cursory
 d = audioop.lin2alaw(data[0], 1)
 self.assertEqual(audioop.alaw2lin(d, 1), data[0])
+ self.assertEqual(audioop.alaw2lin(d, 2), b'\x08\x00\x08\x01\x10\x02')
+ self.assertEqual(audioop.alaw2lin(d, 4),
+ b'\x00\x00\x08\x00\x00\x00\x08\x01\x00\x00\x10\x02')
 
 def test_lin2ulaw(self):
 self.assertEqual(audioop.lin2ulaw(data[0], 1), b'\xff\xe7\xdb')
@@ -119,6 +124,9 @@
 # Cursory
 d = audioop.lin2ulaw(data[0], 1)
 self.assertEqual(audioop.ulaw2lin(d, 1), data[0])
+ self.assertEqual(audioop.ulaw2lin(d, 2), b'\x00\x00\x04\x01\x0c\x02')
+ self.assertEqual(audioop.ulaw2lin(d, 4),
+ b'\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x0c\x02')
 
 def test_mul(self):
 data2 = []
@@ -195,10 +203,15 @@
 self.assertRaises(audioop.error, audioop.lin2lin, data, size, size2)
 self.assertRaises(audioop.error, audioop.ratecv, data, size, 1, 1, 1, state)
 self.assertRaises(audioop.error, audioop.lin2ulaw, data, size)
+ self.assertRaises(audioop.error, audioop.lin2alaw, data, size)
+ self.assertRaises(audioop.error, audioop.lin2adpcm, data, size, state)
+
+ def test_wrongsize(self):
+ data = b'abc'
+ state = None
+ for size in (-1, 3, 5):
 self.assertRaises(audioop.error, audioop.ulaw2lin, data, size)
- self.assertRaises(audioop.error, audioop.lin2alaw, data, size)
 self.assertRaises(audioop.error, audioop.alaw2lin, data, size)
- self.assertRaises(audioop.error, audioop.lin2adpcm, data, size, state)
 self.assertRaises(audioop.error, audioop.adpcm2lin, data, size, state)
 
 def test_main():
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -461,6 +461,9 @@
 Library
 -------
 
+- Issue #13806: The size check in audioop decompression functions was too
+ strict and could reject valid compressed data. Patch by Oleg Plakhotnyuk.
+
 - Issue #13812: When a multiprocessing Process child raises an exception,
 flush stderr after printing the exception traceback.
 
diff --git a/Modules/audioop.c b/Modules/audioop.c
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -1311,7 +1311,7 @@
 &cp, &len, &size) )
 return 0;
 
- if (!audioop_check_parameters(len, size))
+ if (!audioop_check_size(size))
 return NULL;
 
 if (len > PY_SSIZE_T_MAX/size) {
@@ -1380,7 +1380,7 @@
 &cp, &len, &size) )
 return 0;
 
- if (!audioop_check_parameters(len, size))
+ if (!audioop_check_size(size))
 return NULL;
 
 if (len > PY_SSIZE_T_MAX/size) {
@@ -1524,7 +1524,7 @@
 &cp, &len, &size, &state) )
 return 0;
 
- if (!audioop_check_parameters(len, size))
+ if (!audioop_check_size(size))
 return NULL;
 
 /* Decode state, should have (value, step) */
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /