From patchwork Sat Feb 6 17:23:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 25468 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 2CAA94499D5 for ; Sat, 6 Feb 2021 19:24:16 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1927468A03E; Sat, 6 Feb 2021 19:24:16 +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 1FF1B689AEA 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-0003YK-0H 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 8RIUl1qVXljeH8RIUl7eiH; 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:23:01 +0100 Message-Id: <20210206172301.11769-8-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 8/8] avformat/mov: Only detect things that contain a moov or mdat as mov 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" Please test this and provide samples which break with this so a clean probe that works with every sample can be written. (i failed to find a file which fails) This also fixes multiple probetest failures the score = 0 case could be replaced by a small score of some form and the remaining code overall can be simplified further Signed-off-by: Michael Niedermayer --- libavformat/mov.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index 2df6762ec9..d9a6a54083 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7104,6 +7104,7 @@ static int mov_probe(const AVProbeData *p) uint32_t tag; int score = 0; int moov_offset = 0; + int mdat_offset = 0; /* check file header */ offset = 0; @@ -7129,7 +7130,11 @@ static int mov_probe(const AVProbeData *p) /* check for obvious tags */ case MKTAG('m','o','o','v'): moov_offset = offset + 4; + offset += minsize; + continue; // descend into moov case MKTAG('m','d','a','t'): + mdat_offset = offset + 4; + break; 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'): @@ -7160,6 +7165,15 @@ static int mov_probe(const AVProbeData *p) } offset += size; } + + if ((!!moov_offset) + (!!mdat_offset) + (!!score) > 1) { + // We found more than 1 tag and at least either MDAT or MOOV + score = AVPROBE_SCORE_MAX; + } else if (mdat_offset == 4 && p->buf_size > 16384) { // mdat at the start and its too big so we cannot see beyond + score = AVPROBE_SCORE_MAX; + } else + score = 0; + if (score > AVPROBE_SCORE_MAX - 50 && moov_offset) { /* moov atom in the header - we should make sure that this is not a * MOV-packed MPEG-PS */