From patchwork Tue Aug 25 09:35:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xu, Guangxin" X-Patchwork-Id: 21901 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 6A13644BBEC for ; Tue, 25 Aug 2020 12:35:55 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4115F688260; Tue, 25 Aug 2020 12:35:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 21818687F1D for ; Tue, 25 Aug 2020 12:35:47 +0300 (EEST) IronPort-SDR: HSNQKaRmBPpNzk0brni7sQrfAKND+WhZj1N22EWUGEB/TNvBkNMlHL00AqpFS2DHMcfzEdEQmL K2INliQpFZIA== X-IronPort-AV: E=McAfee;i="6000,8403,9723"; a="143851479" X-IronPort-AV: E=Sophos;i="5.76,352,1592895600"; d="scan'208";a="143851479" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2020 02:35:44 -0700 IronPort-SDR: 77QLc4QX3APCWzvNBnH8gyMj4gOA5LU774cJOaU6bz6AxRdYm6IcaGfrIvi05lrcokBankIRwl pQdgSuqZ7FNg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,352,1592895600"; d="scan'208";a="474277666" Received: from skl-e5-server.sh.intel.com ([10.239.43.170]) by orsmga005.jf.intel.com with ESMTP; 25 Aug 2020 02:35:43 -0700 From: Xu Guangxin To: ffmpeg-devel@ffmpeg.org Date: Tue, 25 Aug 2020 17:35:41 +0800 Message-Id: <20200825093541.38010-1-guangxin.xu@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] avcodec/ff_mpv_encode_end: fix a crash for null s->avctx 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: vittorio.giovara@gmail.com, Xu Guangxin MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Steps to reproduce: 1. ./configure --enable-debug=3 --disable-libx264 && make install 2. ffmpeg -i input.mp4 -profile:v baseline output.mp4 -y you will see a crash like this: [mpeg4 @ 0x5555575854c0] [Eval @ 0x7fffffffbf80] Undefined constant or missing '(' in 'baseline' [mpeg4 @ 0x5555575854c0] Unable to parse option value "baseline" [mpeg4 @ 0x5555575854c0] Error setting option profile to value baseline. Thread 1 "ffmpeg" received signal SIGSEGV, Segmentation fault. root cause: If the codec has FF_CODEC_CAP_INIT_CLEANUP flag, and avcodec_open2 got an error before avctx->codec->init, the ff_mpv_encode_end will face a null s->avctx. --- libavcodec/mpegvideo_enc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 09697d89c8..a79309d1b9 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1078,9 +1078,10 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) av_frame_free(&s->tmp_frames[i]); ff_free_picture_tables(&s->new_picture); - ff_mpeg_unref_picture(s->avctx, &s->new_picture); - - av_freep(&s->avctx->stats_out); + if (s->avctx) { + ff_mpeg_unref_picture(s->avctx, &s->new_picture); + av_freep(&s->avctx->stats_out); + } av_freep(&s->ac_stats); if(s->q_chroma_intra_matrix != s->q_intra_matrix ) av_freep(&s->q_chroma_intra_matrix);