ref: 3194dca1668b4c2119ca82900361e26ef95bdfd7
parent: 906c0a229550a957e8f1b9d2cfaeaafe6c96f0a0
author: Paul Brossier <piem@piem.org>
date: Tue Dec 10 12:58:59 EST 2013
ext/aubioproxy.c: improve sizes checks, cast to uint_t Signed-off-by: Paul Brossier <piem@piem.org>
--- a/python/ext/aubioproxy.c
+++ b/python/ext/aubioproxy.c
@@ -35,7 +35,13 @@
// vec = new_fvec (vec->length);
// no need to really allocate fvec, just its struct member
vec = (fvec_t *)malloc(sizeof(fvec_t));
- vec->length = PyArray_SIZE ((PyArrayObject *)array);
+ long length = PyArray_SIZE ((PyArrayObject *)array);
+ if (length > 0) {
+ vec->length = (uint_t)length;
+ } else {
+ PyErr_SetString (PyExc_ValueError, "input array size should be greater than 0");
+ goto fail;
+ }
vec->data = (smpl_t *) PyArray_GETPTR1 ((PyArrayObject *)array, 0);
} else if (PyObject_TypeCheck (input, &PyList_Type)) {
@@ -130,8 +136,20 @@
// no need to really allocate fvec, just its struct member
mat = (fmat_t *)malloc(sizeof(fmat_t));
- mat->length = PyArray_DIM ((PyArrayObject *)array, 1);
- mat->height = PyArray_DIM ((PyArrayObject *)array, 0);
+ long length = PyArray_DIM ((PyArrayObject *)array, 1);
+ if (length > 0) {
+ mat->length = (uint_t)length;
+ } else {
+ PyErr_SetString (PyExc_ValueError, "input array dimension 1 should be greater than 0");
+ goto fail;
+ }
+ long height = PyArray_DIM ((PyArrayObject *)array, 0);
+ if (height > 0) {
+ mat->height = (uint_t)height;
+ } else {
+ PyErr_SetString (PyExc_ValueError, "input array dimension 0 should be greater than 0");
+ goto fail;
+ }
mat->data = (smpl_t **)malloc(sizeof(smpl_t*) * mat->height);
for (i=0; i< mat->height; i++) {
mat->data[i] = (smpl_t*)PyArray_GETPTR1 ((PyArrayObject *)array, i);
--
⑨