diff options
author | Facundo Batista <facundobatista@gmail.com> | 2008-07-07 17:02:59 (GMT) |
---|---|---|
committer | Facundo Batista <facundobatista@gmail.com> | 2008-07-07 17:02:59 (GMT) |
commit | 1a664419bb61079e1fd7a57bc7dc807a3d33443d (patch) | |
tree | 282957b9afcd9ab194563b29a4b47b0ff57471ca | |
parent | 10cf7d947d9d9cc12edef02bfb70db4ff959d8bb (diff) | |
download | cpython-1a664419bb61079e1fd7a57bc7dc807a3d33443d.zip cpython-1a664419bb61079e1fd7a57bc7dc807a3d33443d.tar.gz cpython-1a664419bb61079e1fd7a57bc7dc807a3d33443d.tar.bz2 |
Issue 3306. Better control for a lenght in findmax() function.
-rw-r--r-- | Lib/test/test_audioop.py | 4 | ||||
-rw-r--r-- | Modules/audioop.c | 2 |
2 files changed, 5 insertions, 1 deletions
diff --git a/Lib/test/test_audioop.py b/Lib/test/test_audioop.py index b94be91..8d4f30b 100644 --- a/Lib/test/test_audioop.py +++ b/Lib/test/test_audioop.py @@ -161,6 +161,10 @@ class TestAudioop(unittest.TestCase): self.assertEqual(audioop.getsample(data[1], 2, i), i) self.assertEqual(audioop.getsample(data[2], 4, i), i) + def test_negavitelen(self): + # from issue 3306, previously it segfaulted + self.assertRaises(audioop.error, + audioop.findmax, ''.join( chr(x) for x in xrange(256)), -2392392) def test_main(): run_unittest(TestAudioop) diff --git a/Modules/audioop.c b/Modules/audioop.c index 31e3fa4..767cae6 100644 --- a/Modules/audioop.c +++ b/Modules/audioop.c @@ -575,7 +575,7 @@ audioop_findmax(PyObject *self, PyObject *args) } len1 >>= 1; - if ( len1 < len2 ) { + if ( len2 < 0 || len1 < len2 ) { PyErr_SetString(AudioopError, "Input sample should be longer"); return 0; } |