From patchwork Sat Nov 12 23:44:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 39251 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp1687960pzb; Sat, 12 Nov 2022 15:44:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf6Fm3jUGWwHYIHlo46G7HPEIu6dnciIfZGDCdMKV4jIdQCiSz6gcmAAxKrvlsO4rMIPtuBZ X-Received: by 2002:aa7:d3c1:0:b0:467:30ad:c4ca with SMTP id o1-20020aa7d3c1000000b0046730adc4camr6631062edr.285.1668296668913; Sat, 12 Nov 2022 15:44:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668296668; cv=none; d=google.com; s=arc-20160816; b=UmrHNJKIcLBuMEa4Xl7N4KtFFN/YEDNSOqlq765dMPVpMh6pFqJ+lvMMbqJioTvRHy lEUEbzkuulJIN8bomGdQK2wmclix08bEj+l8MZT4kL/jjXtNUybfdBObelYI+Uhie6r6 j3c7BEyNam6zt8x4/sWZ6skZ6xt0X+DawToLsII8HFdDKVecEhc7VXYZoJEumKOuWA6h TjnxRSv3rBZfll133piXT1iXPzMu8EqylA74mAaYoByel6avfsLtHMUWpEFt6A2nnbaQ OrgD0SGvZ167WgrcbVckVx6S8T5QMMWO7RQbZQbbqXN8nSSoT/o66paUpydxU2tU5UAx dU2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=fz7+siuBxu13bNto6Sm4yu7k11dgzm69ev34gRljokw=; b=a2m0lD+Xx9IfzjrMoPsO2pgVM9Wa6Jms9jFVD6m/uL2N8gPYjtYx6fGLaxKpXeMLCo rSpCfYWvQHQYjkzTeAv0A6x3yffSINbFBmsjTMNspguLCWs+UklrNyWW6w2uCqOdiyHB L2r9nUwf21t3GNf6snPWni5RA7zNo4eUbRQqz8kvvx7UGRaGFtbyKBJ7der+zL3HMVEM DaCaRW36CMxPF0ZiDMCyZJoYBRXQrbf1JjOUhHW+7FSsphmuVJE2IPiDsT1gQoCRoKMb qlc0qaQH9/ew9D3EmQ/MtUeryOCfn7uQ3ghd6QcWbFG6dUxweZn2yF3ohy4FTsKG257b D/eg== 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 gb14-20020a170907960e00b007ae4717bf08si6338497ejc.359.2022.11.12.15.44.28; Sat, 12 Nov 2022 15:44:28 -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 C32C668BA05; Sun, 13 Nov 2022 01:44:11 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2335A68BA05 for ; Sun, 13 Nov 2022 01:44:05 +0200 (EET) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 4D9941BF207 for ; Sat, 12 Nov 2022 23:44:04 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sun, 13 Nov 2022 00:44:01 +0100 Message-Id: <20221112234401.24158-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20221112234401.24158-1-michael@niedermayer.cc> References: <20221112234401.24158-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 3/3] avformat/mxfdec: Reduce overflows in essence_length computation 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 6fI0ZHRN/x7J Fixes: signed integer overflow: -3741319169 - 9223372036823449370 cannot be represented in type 'long' Fixes: 51896/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-513039428681728 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer --- libavformat/mxfdec.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c index e6118e141d..42109cb43a 100644 --- a/libavformat/mxfdec.c +++ b/libavformat/mxfdec.c @@ -100,7 +100,7 @@ typedef struct MXFPartition { uint64_t previous_partition; int index_sid; int body_sid; - int64_t this_partition; + uint64_t this_partition; int64_t essence_offset; ///< absolute offset of essence int64_t essence_length; int32_t kag_size; @@ -3519,8 +3519,12 @@ static void mxf_compute_essence_containers(AVFormatContext *s) p->essence_offset = p->first_essence_klv.offset; /* 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; + if (x < mxf->partitions_count - 1) { + if (mxf->partitions[x+1].this_partition < p->essence_offset) { + p->essence_length = -1; + } else + p->essence_length = mxf->partitions[x+1].this_partition - p->essence_offset; + } if (p->essence_length < 0) { /* next ThisPartition < essence_offset */