From patchwork Sat Feb 6 17:22:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 25466 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 4FF924499D5 for ; Sat, 6 Feb 2021 19:24:14 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 37ABC689D16; Sat, 6 Feb 2021 19:24:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe01-2.mx.upcmail.net (vie01a-dmta-pe01-2.mx.upcmail.net [62.179.121.155]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 09285689A12 for ; Sat, 6 Feb 2021 19:24:04 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe01.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1l8RJS-0003YL-0I for ffmpeg-devel@ffmpeg.org; Sat, 06 Feb 2021 18:24:02 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 8RIUl1qUXljeH8RIUl7ei0; Sat, 06 Feb 2021 18:23:02 +0100 X-Env-Mailfrom: michael@niedermayer.cc X-Env-Rcptto: ffmpeg-devel@ffmpeg.org X-SourceIP: 213.47.68.29 X-CNFS-Analysis: v=2.3 cv=BoHjPrf5 c=1 sm=1 tr=0 a=2hcxjKEKjp0CzLx6oWAm4g==:117 a=2hcxjKEKjp0CzLx6oWAm4g==:17 a=MKtGQD3n3ToA:10 a=1oJP67jkp3AA:10 a=GEAsPZ9sns4A:10 a=ZZnuYtJkoWoA:10 a=VV9h39334b1RBQ_NRcoA:9 a=pHzHmUro8NiASowvMSCR:22 a=Ew2E2A-JSTLzCXPT_086:22 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 6 Feb 2021 18:22:58 +0100 Message-Id: <20210206172301.11769-5-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210206172301.11769-1-michael@niedermayer.cc> References: <20210206172301.11769-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfGD3/E6iPI6p5/xMjPd5XzPd10bpoAdQxGHiPoEiBxclJW7Uy4G2NQrgFy/7l74GVdTmY9u7YOVjsjsKNbBlA9w54Xy3irGaT3HGBGXbHhRqXL37gPtw DLnj8D7hcbJkEr9az213J3LNXXw0gjRnD2iJ9v9MYBHf0mfN02rhvSmC Subject: [FFmpeg-devel] [PATCH 5/8] avformat/mov: Ignore tags with invalid size during probing 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Michael Niedermayer --- libavformat/mov.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 7e634c9ec3..c945586c29 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7109,15 +7109,21 @@ static int mov_probe(const AVProbeData *p) offset = 0; for (;;) { int64_t size; + int minsize = 8; /* ignore invalid offset */ if ((offset + 8) > (unsigned int)p->buf_size) break; size = AV_RB32(p->buf + offset); if (size == 1 && offset + 16 > (unsigned int)p->buf_size) { size = AV_RB64(p->buf+offset + 8); + minsize = 16; } else if (size == 0) { size = p->buf_size - offset; } + if (size < minsize) { + offset += 4; + continue; + } tag = AV_RL32(p->buf + offset + 4); switch(tag) { /* check for obvious tags */ @@ -7127,9 +7133,7 @@ static int mov_probe(const AVProbeData *p) case MKTAG('p','n','o','t'): /* detect movs with preview pics like ew.mov and april.mov */ case MKTAG('u','d','t','a'): /* Packet Video PVAuthor adds this and a lot of more junk */ case MKTAG('f','t','y','p'): - if (size < 8) { - score = FFMAX(score, AVPROBE_SCORE_EXTENSION); - } else if (tag == MKTAG('f','t','y','p') && + if (tag == MKTAG('f','t','y','p') && ( AV_RL32(p->buf + offset + 8) == MKTAG('j','p','2',' ') || AV_RL32(p->buf + offset + 8) == MKTAG('j','p','x',' ') )) { @@ -7154,7 +7158,7 @@ static int mov_probe(const AVProbeData *p) score = FFMAX(score, AVPROBE_SCORE_EXTENSION); break; } - offset = FFMAX(4, size) + offset; + offset += size; } if (score > AVPROBE_SCORE_MAX - 50 && moov_offset != -1) { /* moov atom in the header - we should make sure that this is not a