From: Paul Brossier Date: Mon, 26 Nov 2018 16:22:31 +0000 (+0100) Subject: [mfcc] validate input parameters, safer delete X-Git-Tag: 0.4.9~149 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=5ad5109d733ab6728524f6d253b65d16899e072c;p=aubio.git [mfcc] validate input parameters, safer delete --- diff --git a/src/spectral/mfcc.c b/src/spectral/mfcc.c index da8c97c4..3d189c9a 100644 --- a/src/spectral/mfcc.c +++ b/src/spectral/mfcc.c @@ -55,6 +55,15 @@ new_aubio_mfcc (uint_t win_s, uint_t n_filters, uint_t n_coefs, /* allocate space for mfcc object */ aubio_mfcc_t *mfcc = AUBIO_NEW (aubio_mfcc_t); + if ((sint_t)n_coefs <= 0) { + AUBIO_ERR("mfcc: n_coefs should be > 0, got %d\n", n_coefs); + goto failure; + } + if ((sint_t)samplerate <= 0) { + AUBIO_ERR("mfcc: samplerate should be > 0, got %d\n", samplerate); + goto failure; + } + mfcc->win_s = win_s; mfcc->samplerate = samplerate; mfcc->n_filters = n_filters; @@ -62,6 +71,10 @@ new_aubio_mfcc (uint_t win_s, uint_t n_filters, uint_t n_coefs, /* filterbank allocation */ mfcc->fb = new_aubio_filterbank (n_filters, mfcc->win_s); + + if (!mfcc->fb) + goto failure; + if (n_filters == 40) aubio_filterbank_set_mel_coeffs_slaney (mfcc->fb, samplerate); else @@ -74,24 +87,29 @@ new_aubio_mfcc (uint_t win_s, uint_t n_filters, uint_t n_coefs, mfcc->dct = new_aubio_dct (n_filters); mfcc->output = new_fvec (n_filters); + if (!mfcc->in_dct || !mfcc->dct || !mfcc->output) + goto failure; + mfcc->scale = 1.; return mfcc; + +failure: + del_aubio_mfcc(mfcc); + return NULL; } void del_aubio_mfcc (aubio_mfcc_t * mf) { - - /* delete filterbank */ - del_aubio_filterbank (mf->fb); - - /* delete buffers */ - del_fvec (mf->in_dct); - del_aubio_dct (mf->dct); - del_fvec (mf->output); - - /* delete mfcc object */ + if (mf->fb) + del_aubio_filterbank (mf->fb); + if (mf->in_dct) + del_fvec (mf->in_dct); + if (mf->dct) + del_aubio_dct (mf->dct); + if (mf->output) + del_fvec (mf->output); AUBIO_FREE (mf); }