From c0c24aff728b067ef948f68cbb9bef63be9324c8 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 1 Apr 2017 19:10:08 +0200 Subject: Hotfix crashes for [extreme] time-stretch -- #7305 e.g. stretch-shrink 3712 samples down to 1780. The filter order defines nFact which can become larger than length - 2 leading to out-of-bounds array access. e.g. m_ord = 2 -> nFilt = 2, nFact = 6; process < 7 samples (here 6) --- libs/qm-dsp/dsp/signalconditioning/FiltFilt.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'libs/qm-dsp') diff --git a/libs/qm-dsp/dsp/signalconditioning/FiltFilt.cpp b/libs/qm-dsp/dsp/signalconditioning/FiltFilt.cpp index 89076c150f..03b21138a4 100644 --- a/libs/qm-dsp/dsp/signalconditioning/FiltFilt.cpp +++ b/libs/qm-dsp/dsp/signalconditioning/FiltFilt.cpp @@ -13,6 +13,7 @@ COPYING included with this distribution for more information. */ +#include #include "FiltFilt.h" ////////////////////////////////////////////////////////////////////// @@ -55,6 +56,14 @@ void FiltFilt::process(double *src, double *dst, unsigned int length) if (length == 0) return; + if (length < 2) { + fprintf (stderr, "FiltFilt::process called for %d samples\n", length); + for( i = 0; i < length; i++ ) { + dst[i] = src [i]; + } + return; + } + unsigned int nFilt = m_ord + 1; unsigned int nFact = 3 * ( nFilt - 1); unsigned int nExt = length + 2 * nFact; @@ -79,11 +88,16 @@ void FiltFilt::process(double *src, double *dst, unsigned int length) m_filtScratchIn[ index++ ] = sample0 - src[ i ]; } index = 0; - for( i = 0; i < nFact; i++ ) + for( i = 0; i < nFact && i + 2 < length; i++ ) { m_filtScratchIn[ (nExt - nFact) + index++ ] = sampleN - src[ (length - 2) - i ]; } + for(; i < nFact; i++ ) + { + m_filtScratchIn[ (nExt - nFact) + index++ ] = 0; + } + index = 0; for( i = 0; i < length; i++ ) { -- cgit v1.2.3