From patchwork Tue Dec 7 08:42:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yy X-Patchwork-Id: 32095 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp5947570iog; Tue, 7 Dec 2021 00:42:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJynxqNH94A5fOgz7bkVMj+z0PQUxAgKuISAFheHweTh0u2o34cKV9fE+NA7Vh0Yx94JGW5l X-Received: by 2002:a50:da48:: with SMTP id a8mr6918304edk.155.1638866575076; Tue, 07 Dec 2021 00:42:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638866575; cv=none; d=google.com; s=arc-20160816; b=FSU+DrDyfdH66ay7u+qOl//MUcr2ATDEniLASrE0PBkH71deRDZFWkv3bZJcl3aeNs EkuYO8G0GHOaocHyVKuwrdBdq4V7SVdfj5pcS3rcmT+3zhMEsN30szlcejmdG6sFbA21 2/vUzzMVcM34882bzRmMnGDC56NccZvYGQRdC6+zGCD9sfKqut82PccfYF+KsjpVXsao 4UhnV0KfMbyk86HldxdQKtjJV10bImqn64JI8TFtvtJW5v6JS4fsaxupjPsqtnH1dIEH N/DtrIjjyk5Lz5+PdyOoQwomxAQvDK/T9+Zoe0oZxR7Jrn5wR7F5Pby6vvJrGGnbHAVo D/rA== 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=oAtBQdkM473uErb7IpoLrRiS6QaVK8hP4yyXToEgUfg=; b=fYJ09hM5t4AiEnyC9LnfaOOSuibcewjDJISiS4LJW1cQJiHKSh7CoUejH1Qk5mImmg C9R8NNS1z48gUHL69+K+0RZhRGWsxg+a1MzUl3uITqnvQQPtfACVQHNX61jCRb6fYo/3 UGY5dcjz05Q+lTDjAP+tKYTtRgyPmleNnAAhyyt1kX/LUhw6T8RGHssQIBOsFVs++1Wf FMxnT5VogxHkZZYAFqrx7l0pvDLMQRC1iCcpx+HgN5pPoXKunWSUO9quefe0k+adM3AP HifoYrY4Jsq045LRMyMRpQoJd2N8fv9ZBW6fyP5M5jxSEeqJHz3ctSyisYWfAU0YaFiE 0Ssw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@163.com header.s=s110527 header.b=Oc+DnplA; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=163.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id kv13si15660048ejc.740.2021.12.07.00.42.54; Tue, 07 Dec 2021 00:42:55 -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=@163.com header.s=s110527 header.b=Oc+DnplA; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7742F68A83D; Tue, 7 Dec 2021 10:42:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-m975.mail.163.com (mail-m975.mail.163.com [123.126.97.5]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 385A468A0B7 for ; Tue, 7 Dec 2021 10:42:42 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=Dk4qS 9zUd5v34ySUBN723DXy8l/c31HEbG1kXuEgUUY=; b=Oc+DnplAHAHOneih2OQbw o67iOFSbm2TF/vI+wZ5r598ow0J9zl0ahAGO5LD0Fm59Eupb+zm9MqviG9BFdpd0 aZlFFrhtH/snr64Lit/e1QyKIb/R5TheMteldk9weZPP/n1yKgKl/LL15qx5AWNd JoqOdCl3MjbEhg9DKvYh8w= Received: from localhost.localdomain (unknown [103.107.216.232]) by smtp5 (Coremail) with SMTP id HdxpCgAHWDp9Hq9hTw1LAg--.63120S2; Tue, 07 Dec 2021 16:42:39 +0800 (CST) From: Yu Yang To: ffmpeg-devel@ffmpeg.org Date: Tue, 7 Dec 2021 16:42:35 +0800 Message-Id: <20211207084235.42034-1-young_chelsea@163.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211203093357.65777-1-young_chelsea@163.com> References: <20211203093357.65777-1-young_chelsea@163.com> MIME-Version: 1.0 X-CM-TRANSID: HdxpCgAHWDp9Hq9hTw1LAg--.63120S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7Zr13Gr1rZF4kCrWrKF4fGrg_yoW5JF15pr WrAr13KFyfXF95Crn7t3WFkw1FkFs3G345Krs3t3WUCw4YqF9a9FyI9F1FyF97GFy8XrW2 9Fs5X3ykJ3WjvaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zKZX7hUUUUU= X-Originating-IP: [103.107.216.232] X-CM-SenderInfo: x1rx0wpbfkvzxvhdqiywtou0bp/1tbiNBxiSlaD+v81FAABsw Subject: [FFmpeg-devel] [PATCH v3] fftools/opts: Avoid crash when opts could not be allocated 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: TOTE Robot , Yu Yang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 2qS1mIFsobqo If 'opts' could not be allocated, exiting the program to avoid crash when release it. Before setup_find_stream_info_opts(), checking 'orig_nb_streams' is > 0. If 'orig_nb_streams' == 0, it doesn't need 'opts' to getting streams info. So directly execute avformat_find_stream_info(). Reported-by: TOTE Robot Signed-off-by: Yu Yang --- fftools/cmdutils.c | 5 ++--- fftools/ffmpeg_opt.c | 20 ++++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 3c8e5a82cd..823cc8a632 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -2181,13 +2181,12 @@ AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, int i; AVDictionary **opts; - if (!s->nb_streams) - return NULL; opts = av_calloc(s->nb_streams, sizeof(*opts)); if (!opts) { av_log(NULL, AV_LOG_ERROR, "Could not alloc memory for stream options.\n"); - return NULL; + avformat_close_input(&s); + exit_program(1); } for (i = 0; i < s->nb_streams; i++) opts[i] = filter_codec_opts(codec_opts, s->streams[i]->codecpar->codec_id, diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index a703798586..453f3a21dc 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1191,17 +1191,17 @@ static int open_input_file(OptionsContext *o, const char *filename) choose_decoder(o, ic, ic->streams[i]); if (find_stream_info) { - AVDictionary **opts = setup_find_stream_info_opts(ic, o->g->codec_opts); int orig_nb_streams = ic->nb_streams; - - /* If not enough info to get the stream parameters, we decode the - first frames to get it. (used in mpeg case for example) */ - ret = avformat_find_stream_info(ic, opts); - - for (i = 0; i < orig_nb_streams; i++) - av_dict_free(&opts[i]); - av_freep(&opts); - + if (orig_nb_streams > 0) { + AVDictionary **opts = setup_find_stream_info_opts(ic, o->g->codec_opts); + /* If not enough info to get the stream parameters, we decode the + first frames to get it. (used in mpeg case for example) */ + ret = avformat_find_stream_info(ic, opts); + for (i = 0; i < orig_nb_streams; i++) + av_dict_free(&opts[i]); + av_freep(&opts); + } else + ret = avformat_find_stream_info(ic, NULL); if (ret < 0) { av_log(NULL, AV_LOG_FATAL, "%s: could not find codec parameters\n", filename); if (ic->nb_streams == 0) {