python/ext/py-filterbank.c: check input size
authorPaul Brossier <piem@piem.org>
Tue, 3 May 2016 02:19:28 +0000 (04:19 +0200)
committerPaul Brossier <piem@piem.org>
Tue, 3 May 2016 02:19:28 +0000 (04:19 +0200)
python/ext/py-filterbank.c
python/tests/test_filterbank.py

index 4dbb175..0d93414 100644 (file)
@@ -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;
index ce81974..46fd97e 100755 (executable)
@@ -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()