From 41cae501b7f2089579bf4bd8f938520a37dede55 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Wed, 9 Mar 2022 21:11:47 +0100 Subject: avfilter/af_anlmdn: fix possible array overflow and increase options limits --- libavfilter/af_anlmdn.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) (limited to 'libavfilter/af_anlmdn.c') diff --git a/libavfilter/af_anlmdn.c b/libavfilter/af_anlmdn.c index 141e5f398e..a2c42393b6 100644 --- a/libavfilter/af_anlmdn.c +++ b/libavfilter/af_anlmdn.c @@ -33,8 +33,6 @@ #define WEIGHT_LUT_NBITS 20 #define WEIGHT_LUT_SIZE (1<cache->extended_data[ch]; const float sw = (65536.f / (4 * K + 2)) / sqrtf(s->a); float *dst = (float *)out->extended_data[ch] + s->offset; - const float smooth = s->m; + const float *const weight_lut = s->weight_lut; + const float pdiff_lut_scale = s->pdiff_lut_scale; + const float smooth = fminf(s->m, WEIGHT_LUT_SIZE / pdiff_lut_scale); for (int i = S; i < s->H + S; i++) { float P = 0.f, Q = 0.f; @@ -231,26 +238,24 @@ static int filter_channel(AVFilterContext *ctx, void *arg, int ch, int nb_jobs) } for (int j = 0; j < 2 * S && !ctx->is_disabled; j++) { - const float distance = cache[j]; + float distance = cache[j]; unsigned weight_lut_idx; float w; - if (distance < 0.f) { - cache[j] = 0.f; - continue; - } + if (distance < 0.f) + cache[j] = distance = 0.f; w = distance * sw; if (w >= smooth) continue; - weight_lut_idx = w * s->pdiff_lut_scale; + weight_lut_idx = w * pdiff_lut_scale; av_assert2(weight_lut_idx < WEIGHT_LUT_SIZE); - w = s->weight_lut[weight_lut_idx]; + w = weight_lut[weight_lut_idx]; P += w * f[i - S + j + (j >= S)]; Q += w; } P += f[i]; - Q += 1; + Q += 1.f; switch (om) { case IN_MODE: dst[i - S] = f[i]; break; -- cgit v1.2.3