From patchwork Tue Aug 25 14:09:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21919 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 9060644B6CA for ; Tue, 25 Aug 2020 17:10:34 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7980368AE6E; Tue, 25 Aug 2020 17:10:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f67.google.com (mail-ej1-f67.google.com [209.85.218.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4353068AFA5 for ; Tue, 25 Aug 2020 17:10:27 +0300 (EEST) Received: by mail-ej1-f67.google.com with SMTP id b17so8444836ejq.8 for ; Tue, 25 Aug 2020 07:10:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=506TWpTewRdXloEUJj7dXScmI+Ek7tTZH0uAtzdODGg=; b=CYCfRaUAlnvDUpdV3cf8iu68xGXDc13WZKUvv+hDozSlJ3yQKN+Eq6T+NASSCdAdx7 lMjUDXwJ1ZedCmEmw9N5FIHdypYrefEutBDw3zgKWdiZJbfJlA5oQ9Z+lv39Y3SuxQm8 fMpRznU2qer6cSr5EbcWfB17dQl8Jwp0OYTLvMn/KrAUhsgjP7vK6SKs3PoMc6J/VXtD Vd5bGusuLHiv3X5dTzGyS/RY7Gd6SU+M7dgoEpYbRGTDJF2NLTi5gXJfCAOtxrWMNm1T 19tQJcBKLJAP+OQT0DTdzaUdwaKKDZsrjgmXxNq1JLXOYCeKuqtitlg98/xD9HPFnC8H gW2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=506TWpTewRdXloEUJj7dXScmI+Ek7tTZH0uAtzdODGg=; b=HLozNbBw67DDaLFvijmQz7kz+k54GPqvd9RhQJVV1rwd5oUaHkr/e2/ozyep+uvaq8 aTsBgwBkAjZiP41WLb2ljAaP/V20dLmlDHUTixuCG9UNv5DzZHz4Q/LUKpSyPJqeNXQa uDwE2S/O87PqHpMk65ax+zrHcTbywu6OxeajyZ0QZppPkKaIbisS85KbUtxgxDHapNkm oeQ5qzsWZ+vCDCCti+06SNQCgi9Bs0D8SvjsUhdXzfiesLPnrX+b7RoxpYaegXAYjBtR VLJJ+uKFTTwXvEJUtEmy2fLJe5YqF7rdtA1hDY1zRQBzEwHxIP7bMNBdEeDtlAoLWGnV eLWw== X-Gm-Message-State: AOAM533/L/kRWZNCVI+susXtQsAjrUXEltDSX5AmrvYpe/NreTZkxjTN dTdKVGwgc9V50TSjO2tip4fw3qeR+Z0= X-Google-Smtp-Source: ABdhPJxVw77sMAUCXn3E1v1cB/RNtSZdnEsNWZYqvgQUhups+Q5YA04NxQBij2epMl51ESBYrCWHlA== X-Received: by 2002:a17:906:5f8d:: with SMTP id a13mr10492617eju.226.1598364626235; Tue, 25 Aug 2020 07:10:26 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id k25sm10169806edx.96.2020.08.25.07.10.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Aug 2020 07:10:25 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 25 Aug 2020 16:09:27 +0200 Message-Id: <20200825140927.16433-19-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200825140927.16433-1-andreas.rheinhardt@gmail.com> References: <20200825140927.16433-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 19/19] avfilter/af_headphone: Fix segfault upon allocation failure X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The headphone filter uses a variable number of inpads and allocates them in its init function; if all goes well, the number of inpads coincides with a number stored in the filter's private context. Yet if allocating a subsequent inpad fails, the uninit function nevertheless uses the number stored in the private context to determine the number of inpads to free and not the AVFilterContext's nb_inputs. This will lead to an access beyond the end of the allocated AVFilterContext.input_pads array and an invalid free. Signed-off-by: Andreas Rheinhardt --- This is not the only thing wrong in this filter. Will send a separate patchset for it. libavfilter/af_headphone.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c index 552ad84837..751f4ab53d 100644 --- a/libavfilter/af_headphone.c +++ b/libavfilter/af_headphone.c @@ -812,7 +812,6 @@ static int config_output(AVFilterLink *outlink) static av_cold void uninit(AVFilterContext *ctx) { HeadphoneContext *s = ctx->priv; - int i; av_fft_end(s->ifft[0]); av_fft_end(s->ifft[1]); @@ -834,11 +833,9 @@ static av_cold void uninit(AVFilterContext *ctx) av_freep(&s->data_hrtf[1]); av_freep(&s->fdsp); - for (i = 0; i < s->nb_inputs; i++) { - if (ctx->input_pads && i) - av_freep(&ctx->input_pads[i].name); - } av_freep(&s->in); + for (unsigned i = 1; i < ctx->nb_inputs; i++) + av_freep(&ctx->input_pads[i].name); } #define OFFSET(x) offsetof(HeadphoneContext, x)