From patchwork Thu Dec 14 14:39:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45135 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1225:b0:181:818d:5e7f with SMTP id v37csp4989981pzf; Thu, 14 Dec 2023 06:39:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeLP2/xgXU5dlIRLJTGIMXpQhqvs1BQZI/loZrut8kCh4QKCzow0kBDVUTtve1rikrLuSK X-Received: by 2002:a50:ab17:0:b0:551:eb2b:a000 with SMTP id s23-20020a50ab17000000b00551eb2ba000mr2049141edc.36.1702564765756; Thu, 14 Dec 2023 06:39:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702564765; cv=none; d=google.com; s=arc-20160816; b=UQwqbAV9lL/RSEmyUyLgWcpttS87iIFnge+pzTV74pK5jvqm4cmlOzEp9z0zxnYFW0 oc1NaCFuzi0wTFGraiqZx5T1UlMfZMgbvCz2IWP9tQuH1YY0cPVKieIgkf0iE0Xwir7C oYTH2zjxbFyvKkIbX0XQsClEL7I6hTSDvTa72HQighR/i691uoj4oE6hlzhyLUoUW6pn nYTztqcdOLqMiQxpSX4kixG8Y+D+XQ66PeqP5MXhMtETLOeBttLvsi1vB6Fd+ASZoEmk bVSTg3Y4ZQVTNYPT0+omtHSOdgK9Vj+rqWzLNpusvZsVhjIvCeLGt2tRpwVuw1rKIz1i EtiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=cHDi73d5y97KxBuAEyw18EItzJVZRjxLpA1DKfs0l/M=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=JBBXuUfW/hUftvMDKC37XomWYtVZgq+u62RgtZCqVYpLfQSKAi9ONmf8+BsCAramAG /FqOy53T3044QkVuphkCrJlEHbxPBcieaWLg5pqhBcHFyuJWVgFgV/UwRXyv32Q2YEG+ lccUjHviPsck6XH5tLe/KqgP70oyJjNZ4n/V2tbtBHZ6wH3sSbQDeb170tkHU709EGym yQuJMNFJThQAeKMEaUdL4MWi9nt9+Z2Py6/vCqbLGkQcQu10dBvxYI2gl+T/sD3BJjLO X++r67v4mLHohJ/giHk5q8y4DsAO7p6jk5oAsRnaw3HR/7E5WzYCLbsEgGDROrDUvmV9 CWgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=JQFObAoi; 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 t16-20020a50ab50000000b0055228860911si1429662edc.530.2023.12.14.06.39.24; Thu, 14 Dec 2023 06:39:25 -0800 (PST) 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; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=JQFObAoi; 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 A090468D27E; Thu, 14 Dec 2023 16:39:21 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B05E268D239 for ; Thu, 14 Dec 2023 16:39:14 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 740004B5C8; Thu, 14 Dec 2023 15:39:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1702564754; bh=YWc7VzzpxSf5fsmdo71vRhHWJH8pl1uODFu7EM2Ov0A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JQFObAoiWGAw4GW0OHnW6Hzc9yscSgogPo5QabGylqHrsAFTkIFB493+Ih9dhxmix PxBoG3pgTfYr+IbzmekQGhrkoZSSVElE3VAa/9b+2ASiVXkPGRs22GFd1mznOfm5+T dpQO5oWy7XbhkPKu3wALiRdIsy8P0AiovueZVdwY= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Thu, 14 Dec 2023 15:39:11 +0100 Message-ID: <20231214143911.39198-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20231214030948.GH6420@pb2> References: <20231214030948.GH6420@pb2> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avfilter/formats: set audio fmt lists for vaf filters 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: vGlP5egG5vBN From: Niklas Haas Currently, the logic inside the FF_FILTER_FORMATS_QUERY_FUNC branch prevents this code from running in the event that we have a filter with a single video input and a single audio output, as the resulting audio output link will not have its channel counts / samplerates correctly initialized to their default values, possibly triggering a segfault downstream. An example of such a filter is vaf_spectrumsynth. Although this particular filter already sets up the channel counts and samplerates as part of the query function and therefore avoids triggering this bug, the bug still exists in principle. (And importantly, sets a wrong precedent) --- libavfilter/formats.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libavfilter/formats.c b/libavfilter/formats.c index d1c97daf64..114886aeb2 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -808,16 +808,17 @@ int ff_default_query_formats(AVFilterContext *ctx) /* Intended fallthrough */ case FF_FILTER_FORMATS_PASSTHROUGH: case FF_FILTER_FORMATS_QUERY_FUNC: - type = ctx->nb_inputs ? ctx->inputs [0]->type : - ctx->nb_outputs ? ctx->outputs[0]->type : AVMEDIA_TYPE_VIDEO; - formats = ff_all_formats(type); + type = AVMEDIA_TYPE_UNKNOWN; + formats = ff_all_formats(ctx->nb_inputs ? ctx->inputs [0]->type : + ctx->nb_outputs ? ctx->outputs[0]->type : + AVMEDIA_TYPE_VIDEO); break; } ret = ff_set_common_formats(ctx, formats); if (ret < 0) return ret; - if (type == AVMEDIA_TYPE_AUDIO) { + if (type != AVMEDIA_TYPE_VIDEO) { ret = ff_set_common_all_channel_counts(ctx); if (ret < 0) return ret;