From patchwork Sat Dec 24 19:36:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 39747 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:bc95:b0:ad:ade2:bfd2 with SMTP id fx21csp1574395pzb; Sat, 24 Dec 2022 11:36:33 -0800 (PST) X-Google-Smtp-Source: AMrXdXvfcKjONn/S41UIw6huC/rT74ybDctFzsFqBbCF/3RyH4+7TnyxA8KIPCMyH3gKUT3DLTUT X-Received: by 2002:a05:6402:3224:b0:47d:810a:f410 with SMTP id g36-20020a056402322400b0047d810af410mr15298137eda.24.1671910593250; Sat, 24 Dec 2022 11:36:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671910593; cv=none; d=google.com; s=arc-20160816; b=u3A6weLBVe687yNW2M5yk+1W/HvfeLqWrAWwe9kSVvNjWE+bK4p68R5PTIMetWaL/C tP1lePRM7pm9RkvQAfJDx8Z8Ko1e2hhwEa8JPjRNj1gawoVzS3xO8wjlD1eHNozjlgTl yunIOs2z3yEqUrfFjiYvI4St/GvQ6+OniNkG2uM/DHCwkOkCdrnNL4MihI2ufLATAxpG gd3J+OY9QQNKeu3G/L3Ge87WGyzITbdOKxU1qLTXZsUnOon/cIE27qZPwTSYL+FYA/OL mr1vNBoYTac+iw3ohqRSx2iqHyHDLZXIKx0Krb8eRRiaFx9HmkE2mJVYLTrrXkr5UlLW L3FA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=TcSIKSTgj0uCLgS4CeoMyCaU73H3tVOPGrunlw5q2zY=; b=t1YQKt4gh6hQLsUNVE8PJ/eqti9syvjrkHcbu428rjfq0pImGkVj/Z9xry3sNibh0Y OxR66W68ter9bBF9ozS5XuBmw0TTpyC/VKIPght6lZLE0IWCjU+yLIq3cKXCrWDDDdb3 6pEUSIvghaB8BKt3YZmHibbZgazM20agRTaIn9LChZjzvNU/uXCA+GKJKVeHGi2bZTit qxwvt9X1wBUfqp3gLVmqmSqGiDbdbjF1ss+LEUQ7lHpDuLmEnFZ7V45q3Acsa1Segu54 rgir4jvzPpKw68vJTgETbWA8wixYXGrrXIxQuC6iyWyG2VYfGWqc4lWbVPse3GnvuXlk G55Q== ARC-Authentication-Results: i=1; mx.google.com; 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 c15-20020a056402100f00b0047d7499c995si4885494edu.134.2022.12.24.11.36.32; Sat, 24 Dec 2022 11:36:33 -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; 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 3CF6668BBDA; Sat, 24 Dec 2022 21:36:30 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 194B968BAA7 for ; Sat, 24 Dec 2022 21:36:23 +0200 (EET) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 37FDC240002 for ; Sat, 24 Dec 2022 19:36:21 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 24 Dec 2022 20:36:21 +0100 Message-Id: <20221224193621.4593-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] avformat/mxfdec: Remove this_partition 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 8Vro0ji83UIF Suggested-by: Tomas Härdin Signed-off-by: Michael Niedermayer --- libavformat/mxfdec.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index e6118e141d..0553728253 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -100,7 +100,6 @@ typedef struct MXFPartition { uint64_t previous_partition; int index_sid; int body_sid; - int64_t this_partition; int64_t essence_offset; ///< absolute offset of essence int64_t essence_length; int32_t kag_size; @@ -725,10 +724,14 @@ static int mxf_read_partition_pack(void *arg, AVIOContext *pb, int tag, int size UID op; uint64_t footer_partition; uint32_t nb_essence_containers; + uint64_t this_partition; if (mxf->partitions_count >= INT_MAX / 2) return AVERROR_INVALIDDATA; + if (klv_offset < mxf->run_in) + return AVERROR_INVALIDDATA; + tmp_part = av_realloc_array(mxf->partitions, mxf->partitions_count + 1, sizeof(*mxf->partitions)); if (!tmp_part) return AVERROR(ENOMEM); @@ -771,7 +774,13 @@ static int mxf_read_partition_pack(void *arg, AVIOContext *pb, int tag, int size partition->complete = uid[14] > 2; avio_skip(pb, 4); partition->kag_size = avio_rb32(pb); - partition->this_partition = avio_rb64(pb); + this_partition = avio_rb64(pb); + if (this_partition != klv_offset - mxf->run_in) { + av_log(mxf->fc, AV_LOG_WARNING, + "this_partition %"PRId64" mismatches %"PRId64"\n", + this_partition, klv_offset - mxf->run_in); + this_partition = klv_offset - mxf->run_in; + } partition->previous_partition = avio_rb64(pb); footer_partition = avio_rb64(pb); partition->header_byte_count = avio_rb64(pb); @@ -791,8 +800,8 @@ static int mxf_read_partition_pack(void *arg, AVIOContext *pb, int tag, int size av_dict_set(&s->metadata, "operational_pattern_ul", str, 0); } - if (partition->this_partition && - partition->previous_partition == partition->this_partition) { + if (this_partition && + partition->previous_partition == this_partition) { av_log(mxf->fc, AV_LOG_ERROR, "PreviousPartition equal to ThisPartition %"PRIx64"\n", partition->previous_partition); @@ -800,11 +809,11 @@ static int mxf_read_partition_pack(void *arg, AVIOContext *pb, int tag, int size if (!mxf->parsing_backward && mxf->last_forward_partition > 1) { MXFPartition *prev = mxf->partitions + mxf->last_forward_partition - 2; - partition->previous_partition = prev->this_partition; + partition->previous_partition = prev->pack_ofs - mxf->run_in; } /* if no previous body partition are found point to the header * partition */ - if (partition->previous_partition == partition->this_partition) + if (partition->previous_partition == this_partition) partition->previous_partition = 0; av_log(mxf->fc, AV_LOG_ERROR, "Overriding PreviousPartition with %"PRIx64"\n", @@ -826,7 +835,7 @@ static int mxf_read_partition_pack(void *arg, AVIOContext *pb, int tag, int size "PartitionPack: ThisPartition = 0x%"PRIX64 ", PreviousPartition = 0x%"PRIX64", " "FooterPartition = 0x%"PRIX64", IndexSID = %i, BodySID = %i\n", - partition->this_partition, + this_partition, partition->previous_partition, footer_partition, partition->index_sid, partition->body_sid); @@ -900,7 +909,7 @@ static uint64_t partition_score(MXFPartition *p) score = 3; else score = 1; - return (score << 60) | ((uint64_t)p->this_partition >> 4); + return (score << 60) | ((uint64_t)p->pack_ofs >> 4); } static int mxf_add_metadata_set(MXFContext *mxf, MXFMetadataSet **metadata_set) @@ -3520,14 +3529,14 @@ static void mxf_compute_essence_containers(AVFormatContext *s) /* essence container spans to the next partition */ if (x < mxf->partitions_count - 1) - p->essence_length = mxf->partitions[x+1].this_partition - p->essence_offset; + p->essence_length = mxf->partitions[x+1].pack_ofs - mxf->run_in - p->essence_offset; if (p->essence_length < 0) { /* next ThisPartition < essence_offset */ p->essence_length = 0; av_log(mxf->fc, AV_LOG_ERROR, "partition %i: bad ThisPartition = %"PRIX64"\n", - x+1, mxf->partitions[x+1].this_partition); + x+1, mxf->partitions[x+1].pack_ofs - mxf->run_in); } } }