History

python/ext/py-filterbank.c: check input size

Paul Brossier committed 10 years ago

Commit de0a4921 parent 7aed1232 files · +17 −0Browse files

Showing the changes to python (2 of 2 files). Show all

Unified · Split

2 files
  1. python/ext/py-filterbank.c +7 −0
  2. python/tests/test_filterbank.py +10 −0
python/ext/py-filterbank.c+7−0
@@ -92,6 +92,13 @@ Py_filterbank_do(Py_filterbank * self, PyObject * args) · 91 unmodified lines
92 return NULL;92 return NULL;
93 }93 }
94 94
95 if (self->vec.length != self->win_s / 2 + 1) {
96 PyErr_Format(PyExc_ValueError,
97 "input cvec has length %d, but fft expects length %d",
98 self->vec.length, self->win_s / 2 + 1);
99 return NULL;
100 }
101
95 Py_INCREF(self->out);102 Py_INCREF(self->out);
96 if (!PyAubio_ArrayToCFvec(self->out, &(self->c_out))) {103 if (!PyAubio_ArrayToCFvec(self->out, &(self->c_out))) {
97 return NULL;104 return NULL;
python/tests/test_filterbank.py+10−0
@@ -61,6 +61,16 @@ class aubio_filterbank_test_case(TestCase): · 60 unmodified lines
61 f.set_mel_coeffs_slaney(16000)61 f.set_mel_coeffs_slaney(16000)
62 assert_almost_equal ( expected, f.get_coeffs() )62 assert_almost_equal ( expected, f.get_coeffs() )
63 63
64 def test_filterbank_long_cvec(self):
65 f = filterbank(40, 512)
66 with self.assertRaises(ValueError):
67 f(cvec(1024))
68
69 def test_filterbank_short_cvec(self):
70 f = filterbank(40, 512)
71 with self.assertRaises(ValueError):
72 f(cvec(256))
73
64if __name__ == '__main__':74if __name__ == '__main__':
65 from nose2 import main75 from nose2 import main
66 main()76 main()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t