From 3194dca1668b4c2119ca82900361e26ef95bdfd7 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Tue, 10 Dec 2013 17:58:59 -0500 Subject: [PATCH] ext/aubioproxy.c: improve sizes checks, cast to uint_t Signed-off-by: Paul Brossier --- python/ext/aubioproxy.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/python/ext/aubioproxy.c b/python/ext/aubioproxy.c index 9b7f9179..d3c00949 100644 --- a/python/ext/aubioproxy.c +++ b/python/ext/aubioproxy.c @@ -35,7 +35,13 @@ PyAubio_ArrayToCFvec (PyObject *input) { // 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 @@ PyAubio_ArrayToCFmat (PyObject *input) { // 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); -- 2.11.0