From de0a49250d04d9322d46172196df711494ac756d Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 3 May 2016 04:19:28 +0200 Subject: [PATCH] python/ext/py-filterbank.c: check input size --- python/ext/py-filterbank.c | 7 +++++++ python/tests/test_filterbank.py | 10 ++++++++++ 2 files changed, 17 insertions(+) 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() -- 2.11.0