[FFmpeg-cvslog] avfilter/af_alimiter: fix misbehavior when nb_channels != 2

David Flater git at videolan.org
Tue Aug 23 13:17:27 EEST 2022


ffmpeg | branch: master | David Flater <dave at flaterco.com> | Sun Aug 14 21:53:10 2022 -0400| [d2b6ec1e273d2554c19e4f189adb0cb40acf401e] | committer: Paul B Mahol

avfilter/af_alimiter: fix misbehavior when nb_channels != 2

Some code in alimiter assumes that there are 2 channels, resulting in
clipping if the loudest channel is 3 or above and an out-of-bounds read if
the input is monophonic.  Fix that in 2 places.

Signed-off-by: David Flater <dave at flaterco.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=d2b6ec1e273d2554c19e4f189adb0cb40acf401e
---

 libavfilter/af_alimiter.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/libavfilter/af_alimiter.c b/libavfilter/af_alimiter.c
index 622dc66324..c683c4bcf4 100644
--- a/libavfilter/af_alimiter.c
+++ b/libavfilter/af_alimiter.c
@@ -194,10 +194,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
             } else {
                 for (i = s->nextiter; i < s->nextiter + s->nextlen; i++) {
                     int j = i % buffer_size;
-                    double ppeak, pdelta;
+                    double ppeak = 0, pdelta;
 
-                    ppeak = fabs(buffer[nextpos[j]]) > fabs(buffer[nextpos[j] + 1]) ?
-                            fabs(buffer[nextpos[j]]) : fabs(buffer[nextpos[j] + 1]);
+                    for (c = 0; c < channels; c++) {
+                        ppeak = FFMAX(ppeak, fabs(buffer[nextpos[j] + c]));
+                    }
                     pdelta = (limit / peak - limit / ppeak) / (((buffer_size - nextpos[j] + s->pos) % buffer_size) / channels);
                     if (pdelta < nextdelta[j]) {
                         nextdelta[j] = pdelta;
@@ -241,14 +242,16 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
                 s->delta = get_rdelta(s, release, inlink->sample_rate,
                                       peak, limit, s->att, 1);
                 if (s->nextlen > 1) {
+                    double ppeak = 0, pdelta;
                     int pnextpos = nextpos[(s->nextiter + 1) % buffer_size];
-                    double ppeak = fabs(buffer[pnextpos]) > fabs(buffer[pnextpos + 1]) ?
-                                                            fabs(buffer[pnextpos]) :
-                                                            fabs(buffer[pnextpos + 1]);
-                    double pdelta = (limit / ppeak - s->att) /
-                                    (((buffer_size + pnextpos -
-                                    ((s->pos + channels) % buffer_size)) %
-                                    buffer_size) / channels);
+
+                    for (c = 0; c < channels; c++) {
+                        ppeak = FFMAX(ppeak, fabs(buffer[pnextpos + c]));
+                    }
+                    pdelta = (limit / ppeak - s->att) /
+                             (((buffer_size + pnextpos -
+                             ((s->pos + channels) % buffer_size)) %
+                             buffer_size) / channels);
                     if (pdelta < s->delta)
                         s->delta = pdelta;
                 }



More information about the ffmpeg-cvslog mailing list