From: David Flater <dave@flaterco.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] avfilter/af_alimiter: fix misbehavior when nb_channels != 2
Date: Tue, 23 Aug 2022 18:49:29 -0400
Message-ID: <78a0e04c-79e4-df98-c744-e6e759f2b64e@flaterco.com> (raw)
In-Reply-To: <80c09a85-3421-1526-ab7c-b0b3b14f9996@flaterco.com>
This is a friendly reminder.
Cc: Paul B Mahol <onemda@gmail.com>
On 2022-08-14 21:53, David Flater wrote:
> 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@flaterco.com>
> ---
> 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;
> }
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2022-08-23 22:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-15 1:53 David Flater
2022-08-23 22:49 ` David Flater [this message]
2022-08-31 13:59 ` Paul B Mahol
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=78a0e04c-79e4-df98-c744-e6e759f2b64e@flaterco.com \
--to=dave@flaterco.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git