summaryrefslogtreecommitdiff
path: root/libs/qm-dsp
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2017-04-01 19:10:08 +0200
committerRobin Gareus <robin@gareus.org>2017-04-01 19:16:12 +0200
commitc0c24aff728b067ef948f68cbb9bef63be9324c8 (patch)
tree00c636fd1ab5e9ba6d265baf13f523b633be7bdf /libs/qm-dsp
parent2513aad1edf7301921af7a025e23d9a2a6f79502 (diff)
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)
Diffstat (limited to 'libs/qm-dsp')
-rw-r--r--libs/qm-dsp/dsp/signalconditioning/FiltFilt.cpp16
1 files changed, 15 insertions, 1 deletions
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 <stdio.h>
#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++ )
{