From patchwork Mon Feb 15 16:55:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 25640 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 AB09A44B8A3 for ; Mon, 15 Feb 2021 18:56:04 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7F132688057; Mon, 15 Feb 2021 18:56:04 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DD8626800E0 for ; Mon, 15 Feb 2021 18:55:57 +0200 (EET) Received: by mail-wr1-f42.google.com with SMTP id 7so9797055wrz.0 for ; Mon, 15 Feb 2021 08:55:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:reply-to:mime-version :content-transfer-encoding; bh=hSVOLUNkwKSMyeYkW+5kMINAlWpMzBYDbezmlOk0/MA=; b=rJvtcW41/VGWxcFrrx9WeqtcMCtwF5fWVBcGYjDcXIFBQRRruB3MuxMQFxQzYXq/ru GhnGyKp/vAVyzpfoBKqo9mHyPQIGnZtOQ2XKd3BttdGFBEzmpyaLnfTdXWpb6Hb/DdoO X+P8TRcliaq/MdVYscsnzAu2eFhGD3s+HM2uV8jMuhLd1BHT2F1QeVY2vSBrrghh6+S9 HNWAeyoLc69FL3BNGRu+hoDWS7/jiXLMDv7IRuNbxzi2HdbNZesBzOoMCBguCut9HEea J7KhkdijhHlW4RZUY9ZCEIplPpN8NIfMs2P2HJUfMWsOc1B9/z9jRxx0DS29MRagSn1a ZD2w== 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:reply-to :mime-version:content-transfer-encoding; bh=hSVOLUNkwKSMyeYkW+5kMINAlWpMzBYDbezmlOk0/MA=; b=SnvBlTmm+04cxUt6p0XPpUkWEoCPTroPIbtIl8ttU30RaOqcAu9bZYWMsbZCjlfucn mLHw7+VbDzroZuT0UU4rG93B7z2Lwf+GBIlfhZfdSGleESC3jd5dqp6l6Zq1dXRYRjVQ q3SmNqIt1Ut87eHkLcw86OEh1L3PhFDvmdmoVPikuwtLae1BcEtkRKkZ0QyH0R5OpVjP S+vefAzSPk0uMOvPRebM+Qe9u4mQITT8DqDnOAgScJM73HClyX8rvX+omQoSFB/ZZkd7 Bs4Su1H1mK/yOf159I8A1NCfmswBQm0qKvHB1+8gAvtr/E1POuzYOz8z2Zy41QyuHvgd vL1A== X-Gm-Message-State: AOAM5323fCWGxqPZl/9j2qFukAU4/BrdUKIavlJucnGIhq7FJEdv1NZ3 dLiA9kw/1CqDb22kmR6+jpDifUT4w1k= X-Google-Smtp-Source: ABdhPJz7vF9VFCOz4lIbRqn6u+++uvGVo46WaGBogQkjBvrcpnvX/mwDFj3pqeE+a00PXnJQ58pAbg== X-Received: by 2002:adf:9148:: with SMTP id j66mr20373590wrj.28.1613408157107; Mon, 15 Feb 2021 08:55:57 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id b2sm24531855wrv.73.2021.02.15.08.55.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Feb 2021 08:55:56 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 15 Feb 2021 17:55:44 +0100 Message-Id: <20210215165549.667105-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 1/6] avformat/mxfenc: Never set codec_ul UID to NULL 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" mxf distinguishes codec profiles by different UIDs and therefore needs to check that the input is actually compatible with mxf (i.e. if there is a defined UID for it). If not, then sometimes the UID would be set to NULL and writing the (video) packet would fail. Yet the following audio packet would trigger writing the header (which has been postponed because the UID is not known at the start) and if the UID is NULL, this can lead to segfaults. This commit therefore stops setting the UID to NULL if the input is incompatible with mxf (it has initially been set to a generic value in mxf_write_header()). Fixes #7993. Signed-off-by: Andreas Rheinhardt --- This has already been sent earlier [1], yet it hasn't been applied because Baptiste wanted it to be fixed by making sure that it is always the video track that triggers writing the header. In a discussion on IRC Tomas indicated that he wants both fixes for this bug and I will therefore apply this here tomorrow unless there are objections. [1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-February/257755.html libavformat/mxfenc.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index 0b399178b5..509cae8442 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2020,7 +2020,6 @@ static int mxf_parse_prores_frame(AVFormatContext *s, AVStream *st, AVPacket *pk if (mxf->header_written) return 1; - sc->codec_ul = NULL; profile = st->codecpar->profile; for (i = 0; i < FF_ARRAY_ELEMS(mxf_prores_codec_uls); i++) { if (profile == mxf_prores_codec_uls[i].profile) { @@ -2028,7 +2027,7 @@ static int mxf_parse_prores_frame(AVFormatContext *s, AVStream *st, AVPacket *pk break; } } - if (!sc->codec_ul) + if (i == FF_ARRAY_ELEMS(mxf_prores_codec_uls)) return 0; sc->frame_size = pkt->size; @@ -2074,7 +2073,6 @@ static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt if (pkt->size < 43) return 0; - sc->codec_ul = NULL; cid = AV_RB32(pkt->data + 0x28); for (i = 0; i < FF_ARRAY_ELEMS(mxf_dnxhd_codec_uls); i++) { if (cid == mxf_dnxhd_codec_uls[i].cid) { @@ -2082,7 +2080,7 @@ static int mxf_parse_dnxhd_frame(AVFormatContext *s, AVStream *st, AVPacket *pkt break; } } - if (!sc->codec_ul) + if (i == FF_ARRAY_ELEMS(mxf_dnxhd_codec_uls)) return 0; sc->component_depth = 0; @@ -2245,6 +2243,7 @@ static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st, const uint8_t *buf = pkt->data; const uint8_t *buf_end = pkt->data + pkt->size; const uint8_t *nal_end; + const UID *codec_ul = NULL; uint32_t state = -1; int extra_size = 512; // support AVC Intra files without SPS/PPS header int i, frame_size, slice_type, has_sps = 0, intra_only = 0, ret; @@ -2315,12 +2314,11 @@ static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st, if (!has_sps) sc->interlaced = st->codecpar->field_order != AV_FIELD_PROGRESSIVE ? 1 : 0; - sc->codec_ul = NULL; frame_size = pkt->size + extra_size; for (i = 0; i < FF_ARRAY_ELEMS(mxf_h264_codec_uls); i++) { if (frame_size == mxf_h264_codec_uls[i].frame_size && sc->interlaced == mxf_h264_codec_uls[i].interlaced) { - sc->codec_ul = &mxf_h264_codec_uls[i].uid; + codec_ul = &mxf_h264_codec_uls[i].uid; sc->component_depth = 10; // AVC Intra is always 10 Bit sc->aspect_ratio = (AVRational){ 16, 9 }; // 16:9 is mandatory for broadcast HD st->codecpar->profile = mxf_h264_codec_uls[i].profile; @@ -2334,17 +2332,18 @@ static int mxf_parse_h264_frame(AVFormatContext *s, AVStream *st, mxf_h264_codec_uls[i].profile == sps->profile_idc && (mxf_h264_codec_uls[i].intra_only < 0 || mxf_h264_codec_uls[i].intra_only == intra_only)) { - sc->codec_ul = &mxf_h264_codec_uls[i].uid; + codec_ul = &mxf_h264_codec_uls[i].uid; st->codecpar->profile = sps->profile_idc; st->codecpar->level = sps->level_idc; // continue to check for avc intra } } - if (!sc->codec_ul) { + if (!codec_ul) { av_log(s, AV_LOG_ERROR, "h264 profile not supported\n"); return 0; } + sc->codec_ul = codec_ul; return 1; } @@ -2441,9 +2440,13 @@ static int mxf_parse_mpeg2_frame(AVFormatContext *s, AVStream *st, } } } - if (s->oformat != &ff_mxf_d10_muxer) - sc->codec_ul = mxf_get_mpeg2_codec_ul(st->codecpar); - return !!sc->codec_ul; + if (s->oformat != &ff_mxf_d10_muxer) { + const UID *codec_ul = mxf_get_mpeg2_codec_ul(st->codecpar); + if (!codec_ul) + return 0; + sc->codec_ul = codec_ul; + } + return 1; } static uint64_t mxf_parse_timestamp(int64_t timestamp64)