From: Paul Brossier Date: Tue, 3 May 2016 02:19:28 +0000 (+0200) Subject: python/ext/py-filterbank.c: check input size X-Git-Tag: 0.4.4~300^2~121 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=de0a49250d04d9322d46172196df711494ac756d;p=aubio.git python/ext/py-filterbank.c: check input size --- diff --git a/python/ext/py-filterbank.c b/python/ext/py-filterbank.c index 4dbb1752..0d93414c 100644 --- a/python/ext/py-filterbank.c +++ b/python/ext/py-filterbank.c @@ -92,6 +92,13 @@ Py_filterbank_do(Py_filterbank * self, PyObject * args) return NULL; } + if (self->vec.length != self->win_s / 2 + 1) { + PyErr_Format(PyExc_ValueError, + "input cvec has length %d, but fft expects length %d", + self->vec.length, self->win_s / 2 + 1); + return NULL; + } + Py_INCREF(self->out); if (!PyAubio_ArrayToCFvec(self->out, &(self->c_out))) { return NULL; diff --git a/python/tests/test_filterbank.py b/python/tests/test_filterbank.py index ce819743..46fd97e8 100755 --- a/python/tests/test_filterbank.py +++ b/python/tests/test_filterbank.py @@ -61,6 +61,16 @@ class aubio_filterbank_test_case(TestCase): f.set_mel_coeffs_slaney(16000) assert_almost_equal ( expected, f.get_coeffs() ) + def test_filterbank_long_cvec(self): + f = filterbank(40, 512) + with self.assertRaises(ValueError): + f(cvec(1024)) + + def test_filterbank_short_cvec(self): + f = filterbank(40, 512) + with self.assertRaises(ValueError): + f(cvec(256)) + if __name__ == '__main__': from nose2 import main main()