python/ext/py-phasevoc.c: add input size checks
authorPaul Brossier <piem@piem.org>
Mon, 2 May 2016 10:05:39 +0000 (12:05 +0200)
committerPaul Brossier <piem@piem.org>
Mon, 2 May 2016 10:05:39 +0000 (12:05 +0200)
python/ext/py-phasevoc.c

index 0c9e2c2..71bb5d5 100644 (file)
@@ -102,6 +102,13 @@ Py_pvoc_do(Py_pvoc * self, PyObject * args)
     return NULL;
   }
 
+  if (self->vecin.length != self->hop_s) {
+    PyErr_Format(PyExc_ValueError,
+                 "input fvec has length %d, but pvoc expects length %d",
+                 self->vecin.length, self->hop_s);
+    return NULL;
+  }
+
   Py_INCREF(self->output);
   if (!PyAubio_PyCvecToCCvec (self->output, &(self->c_output))) {
     return NULL;
@@ -131,6 +138,13 @@ Py_pvoc_rdo(Py_pvoc * self, PyObject * args)
     return NULL;
   }
 
+  if (self->cvecin.length != self->win_s / 2 + 1) {
+    PyErr_Format(PyExc_ValueError,
+                 "input cvec has length %d, but pvoc expects length %d",
+                 self->cvecin.length, self->win_s / 2 + 1);
+    return NULL;
+  }
+
   Py_INCREF(self->routput);
   if (!PyAubio_ArrayToCFvec(self->routput, &(self->c_routput)) ) {
     return NULL;