From patchwork Mon Aug 15 01:53:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Flater X-Patchwork-Id: 37279 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3d0d:b0:8d:a68e:8a0e with SMTP id y13csp1034730pzi; Sun, 14 Aug 2022 18:53:22 -0700 (PDT) X-Google-Smtp-Source: AA6agR6P9o5gP/7WGOeTUzulTugc+56ji71DNW2TTFrAsMQFPFsikAWOmpSm6/Du7fQInV7fAGK4 X-Received: by 2002:a17:906:ef8b:b0:730:d348:61b9 with SMTP id ze11-20020a170906ef8b00b00730d34861b9mr9110646ejb.350.1660528402168; Sun, 14 Aug 2022 18:53:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660528402; cv=none; d=google.com; s=arc-20160816; b=uvqKOGOHk3/Pg9f42UMuYs8qSObaNikxs99WmNXMWZFBbbGTGFp+kispf3oVRRzCI0 hj0+q6PhGAMkkeELZNeTEfz6GMptjCoflukrzDf1oqdB+T839WfdfGWmeJI6tsKo4X3m pjaSTIT19SM6ZxY348Lkn8jupIe+VQY0+3V3M6FQ5Vzx8B0rHowrW80VF6IdVuU6u2T8 BudIUAT32oDBEYaaqrOZ2VvqOby2uEE2NMkQmn33QCdp/cNqyRVpUJaOR4Hg3koje0BN pFb+qpteTDEO5qQWG0LsFjOpFNAZ1GQIgS1mzoGJ1f+jD4/UUCtcSTvE2GU49f/iyRfU R/sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:content-language:to:from:user-agent:mime-version :date:message-id:delivered-to; bh=+xUpEZhZH/6Gxdqw80f1wLUhDQAEgp2X43rbDvlOX/s=; b=PB9Wa4aImL/vWbX7G0befbWiu/th9jXKT77yWciUMXDQL1b8HJf+8sVQcyofte72pZ aTs6+2xdZCTOQftR6a9F9S3fNx2GusblX89JJnyx/6fsNW9PyqNpNcdvu62BOt161ciQ BxG1NK08Wl7bYVt+IOKkLq9PUGva+gj02yEQ8UV3WGHum9F/zv/cON/BW+SptDd9NJsc Whmoh5RInieAoEgkniP/vEUYaYYQsT1Neg9toL+J22NSfCy22dnjw1UwekU8MQE8cibs /K14BVfSjtIldHeyA0PS0wZO4VregFINKudM6xG6aM+7xbC+epcK/KCHNVmkIHP9t+D8 Z1nw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id r20-20020a056402035400b0043de9c6edd7si6088662edw.340.2022.08.14.18.53.21; Sun, 14 Aug 2022 18:53:22 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 81B9D68B92B; Mon, 15 Aug 2022 04:53:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nupi.pair.com (nupi.pair.com [209.68.5.149]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2C71568AF3B for ; Mon, 15 Aug 2022 04:53:11 +0300 (EEST) Received: from nupi.pair.com (localhost [127.0.0.1]) by nupi.pair.com (Postfix) with ESMTP id 8F7514B1E6; Sun, 14 Aug 2022 21:53:09 -0400 (EDT) Received: from [192.168.0.2] (pool-108-45-159-176.washdc.fios.verizon.net [108.45.159.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by nupi.pair.com (Postfix) with ESMTPSA id 55C014B1EE; Sun, 14 Aug 2022 21:53:09 -0400 (EDT) Message-ID: <80c09a85-3421-1526-ab7c-b0b3b14f9996@flaterco.com> Date: Sun, 14 Aug 2022 21:53:10 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 From: David Flater To: ffmpeg-devel@ffmpeg.org Content-Language: en-US X-Scanned-By: mailmunge 3.09 on 209.68.5.149 Subject: [FFmpeg-devel] [PATCH] avfilter/af_alimiter: fix misbehavior when nb_channels != 2 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: hOyaC+jz+g5V 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 --- 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; }