From patchwork Fri Dec 4 23:48:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 24351 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 7DB62449BE5 for ; Sat, 5 Dec 2020 01:48:20 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 55FBB68A62A; Sat, 5 Dec 2020 01:48:20 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ed1-f67.google.com (mail-ed1-f67.google.com [209.85.208.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C9E3F68A0F1 for ; Sat, 5 Dec 2020 01:48:13 +0200 (EET) Received: by mail-ed1-f67.google.com with SMTP id u19so7602504edx.2 for ; Fri, 04 Dec 2020 15:48:13 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=dJY20OoMnBETM1imJU7R+fdtwU8IIKdL1MiLwptPiNs=; b=ooXQGt5ogmkcpP3NZJHQPUO2qlw8ywtmhg9lZDC7jmVmwt9+nda0ywHy1seK2/GSoZ hj0NlhOTJaOFB8ip256tZf/CXzurUkGqZ9ELNpP/2UgvMYl6VrzbbSyOfluX/R5VSvAw H/bYlC3/LJFRIPUVztNaiRXtrWdWO2L9Qcaw1h1m4eosAy+f+I5JON0T6AGXbMeHt276 2bWzTWKDS0pjhfnYR/Whlu3HLfXCpRSCzA4+uW9fgmCmEZLmPTDixsZamr9rlLZu7S8I hR5LjWWWDLEzimprun/G/6yWqv8H0wg5/bqdS3owrF/OCTJbsHGrLehUtUaj3nDTECyV Oebw== 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=dJY20OoMnBETM1imJU7R+fdtwU8IIKdL1MiLwptPiNs=; b=SUQFUQuc5b/YKS2DJnM+Le4ygfLOWKdryC4MYfyOSdC2SjVhEdJ3zDA1TwQHAFcsi1 1TzznfAXz8ZPmp0ZCykynO8kXWjBedA9NQqjr9WAPhwbPzreyd+s4a5sJwQ3x7zGumyo m7usllueUKto4+pTma/Qcv24dmbcInkLqROt1XWRL4b9U7T689Cckb0IZUJcBPyCPuI/ UCknIampuA+xLmQIQusPLO6L4zFJ38zoJmaqzS20uEeIu9V9M+qlI+UQYDSvjFSMW1pz rv6Cs3NoLtjFJrzbtyh4Wqab9Labh3XfGOBRTdCuuChFwMlHiTlu26KuD1P4/Ecxb+MT wtmQ== X-Gm-Message-State: AOAM533NAO+FmAn/qmv1abOO6w1eVmOlvJ//M62+KfH577jk1LJbNP8F zNLFjMlN1j9FKHb6saahgEkpeXUInCD78g== X-Google-Smtp-Source: ABdhPJzCZgtEQ4i+dABwLrIVqG1ulPc2wVTjRCK0wHEABPW8Aw0/schUfev/MXsX4k7ikztm1DCYjA== X-Received: by 2002:a50:8741:: with SMTP id 1mr10019550edv.349.1607125693002; Fri, 04 Dec 2020 15:48:13 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc1aa4b.dynamic.kabel-deutschland.de. [188.193.170.75]) by smtp.gmail.com with ESMTPSA id op5sm4052656ejb.43.2020.12.04.15.48.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 15:48:12 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 5 Dec 2020 00:48:06 +0100 Message-Id: <20201204234806.1509656-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201204225740.1506052-1-andreas.rheinhardt@gmail.com> References: <20201204225740.1506052-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avformat/mxfenc: Discard audio until valid video has been received 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" Normally, video packets are muxed before audio packets for mxf (there is a dedicated interleave function for this); furthermore the first (video) packet triggers writing the actual header. Yet when the first video packet fails the checks performed on it, codec_ul (a value set based upon properties of the bitstream which necessitates actually inspecting packets) may be NULL; the next packet written (an audio packet) will then trigger outputting the header and this leads to a segfault because codec_ul is dereferenced (this is ticket #7993). Therefore this commit discards audio packets until a valid video packet has been received, fixing said ticket. Signed-off-by: Andreas Rheinhardt --- This implements what I had originally in mind to fix said ticket and it is also what Baptiste Coudurier wanted [1]. The main obstacle in fixing it was fixing the mxf-d10-user-comments test (with this patch, the old test would output nothing at all). [1]: https://ffmpeg.org/pipermail/ffmpeg-devel/2020-March/257900.html libavformat/mxfenc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libavformat/mxfenc.c b/libavformat/mxfenc.c index d8678c9d25..2b0b7342a7 100644 --- a/libavformat/mxfenc.c +++ b/libavformat/mxfenc.c @@ -2843,6 +2843,13 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) MXFIndexEntry ie = {0}; int err; + if (!mxf->header_written && pkt->stream_index != 0 && + s->oformat != &ff_mxf_opatom_muxer) { + av_log(s, AV_LOG_ERROR, "Received non-video packet before " + "header has been written\n"); + return AVERROR_INVALIDDATA; + } + if (!mxf->cbr_index && !mxf->edit_unit_byte_count && !(mxf->edit_units_count % EDIT_UNITS_PER_BODY)) { if ((err = av_reallocp_array(&mxf->index_entries, mxf->edit_units_count + EDIT_UNITS_PER_BODY, sizeof(*mxf->index_entries))) < 0) {