From c4b354abd7e46611f9209891b63038a3423a63c4 Mon Sep 17 00:00:00 2001 From: Alexandre Ratchov Date: Mon, 5 Jul 2021 10:30:37 +0200 Subject: [PATCH] Fix off-by-one array access when 64 channel stream is resampled --- aucat/dsp.c | 6 +++--- sndiod/dsp.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/aucat/dsp.c b/aucat/dsp.c index 085b8e8..523d3b8 100644 --- a/aucat/dsp.c +++ b/aucat/dsp.c @@ -429,7 +429,7 @@ resamp_do(struct resamp *p, adata_t *in, adata_t *out, int icnt, int ocnt) if (ofr == 0) break; - for (c = nch; c > 0; c--) + for (c = 0; c < nch; c++) f[c] = 0; q = diff * p->filt_step; @@ -442,7 +442,7 @@ resamp_do(struct resamp *p, adata_t *in, adata_t *out, int icnt, int ocnt) ds = resamp_filt[qi + 1] - s; s += (int64_t)qf * ds >> RESAMP_STEP_BITS; ctx = ctxbuf; - for (c = nch; c > 0; c--) { + for (c = 0; c < nch; c++) { f[c] += (int64_t)ctx[n] * s; ctx += RESAMP_NCTX; } @@ -450,7 +450,7 @@ resamp_do(struct resamp *p, adata_t *in, adata_t *out, int icnt, int ocnt) n = (n + 1) & (RESAMP_NCTX - 1); } - for (c = nch; c > 0; c--) { + for (c = 0; c < nch; c++) { s = f[c] >> RESAMP_BITS; s = (int64_t)s * p->filt_cutoff >> RESAMP_BITS; #if ADATA_BITS == 16 diff --git a/sndiod/dsp.c b/sndiod/dsp.c index a23c765..fd75a14 100644 --- a/sndiod/dsp.c +++ b/sndiod/dsp.c @@ -321,7 +321,7 @@ resamp_do(struct resamp *p, adata_t *in, adata_t *out, int todo) todo--; } else { - for (c = nch; c > 0; c--) + for (c = 0; c < nch; c++) f[c] = 0; q = diff * p->filt_step; @@ -334,7 +334,7 @@ resamp_do(struct resamp *p, adata_t *in, adata_t *out, int todo) ds = resamp_filt[qi + 1] - s; s += (int64_t)qf * ds >> RESAMP_STEP_BITS; ctx = ctxbuf; - for (c = nch; c > 0; c--) { + for (c = 0; c < nch; c++) { f[c] += (int64_t)ctx[n] * s; ctx += RESAMP_NCTX; } @@ -342,7 +342,7 @@ resamp_do(struct resamp *p, adata_t *in, adata_t *out, int todo) n = (n + 1) & (RESAMP_NCTX - 1); } - for (c = nch; c > 0; c--) { + for (c = 0; c < nch; c++) { s = f[c] >> RESAMP_BITS; s = (int64_t)s * p->filt_cutoff >> RESAMP_BITS; #if ADATA_BITS == 16