From patchwork Sat Feb 6 17:22:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 25465 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 6616F4499D5 for ; Sat, 6 Feb 2021 19:24:13 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 309176891E2; Sat, 6 Feb 2021 19:24:13 +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 89FEF680352 for ; Sat, 6 Feb 2021 19:24:03 +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 1l8RJR-0003YJ-09 for ffmpeg-devel@ffmpeg.org; Sat, 06 Feb 2021 18:24:01 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 8RITl1qT2ljeH8RITl7eha; Sat, 06 Feb 2021 18:23:01 +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 From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 6 Feb 2021 18:22:54 +0100 Message-Id: <20210206172301.11769-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfL4Kw8OQfGnn6YO5T+gHxIM1G8Vh3+IvqRvjJ8oOJ3ERhHRRr5qekVFEc6DfTnEB8XlEe28Zcw3gkwbNURKCPILgh5ZJX9J8lHotsKaSzW9QpU0iyXIC VNetsqAL+e0pD/dmUgV9DS6ApACCV0zQvhhofXvmOENeFXDhr16rXkt1 Subject: [FFmpeg-devel] [PATCH 1/8] avformat/mov: factor size out of probe code 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 | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 8eacf2cc04..9406e42f49 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7108,9 +7108,11 @@ static int mov_probe(const AVProbeData *p) /* check file header */ offset = 0; for (;;) { + int64_t size; /* ignore invalid offset */ if ((offset + 8) > (unsigned int)p->buf_size) break; + size = AV_RB32(p->buf + offset); tag = AV_RL32(p->buf + offset + 4); switch(tag) { /* check for obvious tags */ @@ -7120,8 +7122,8 @@ 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 (AV_RB32(p->buf+offset) < 8 && - (AV_RB32(p->buf+offset) != 1 || + if (size < 8 && + (size != 1 || offset + 12 > (unsigned int)p->buf_size || AV_RB64(p->buf+offset + 8) == 0)) { score = FFMAX(score, AVPROBE_SCORE_EXTENSION); @@ -7133,7 +7135,7 @@ static int mov_probe(const AVProbeData *p) } else { score = AVPROBE_SCORE_MAX; } - offset = FFMAX(4, AV_RB32(p->buf+offset)) + offset; + offset = FFMAX(4, size) + offset; break; /* those are more common words, so rate then a bit less */ case MKTAG('e','d','i','w'): /* xdcam files have reverted first tags */ @@ -7142,7 +7144,7 @@ static int mov_probe(const AVProbeData *p) case MKTAG('j','u','n','k'): case MKTAG('p','i','c','t'): score = FFMAX(score, AVPROBE_SCORE_MAX - 5); - offset = FFMAX(4, AV_RB32(p->buf+offset)) + offset; + offset = FFMAX(4, size) + offset; break; case MKTAG(0x82,0x82,0x7f,0x7d): case MKTAG('s','k','i','p'): @@ -7150,10 +7152,10 @@ static int mov_probe(const AVProbeData *p) case MKTAG('p','r','f','l'): /* if we only find those cause probedata is too small at least rate them */ score = FFMAX(score, AVPROBE_SCORE_EXTENSION); - offset = FFMAX(4, AV_RB32(p->buf+offset)) + offset; + offset = FFMAX(4, size) + offset; break; default: - offset = FFMAX(4, AV_RB32(p->buf+offset)) + offset; + offset = FFMAX(4, size) + offset; } } if (score > AVPROBE_SCORE_MAX - 50 && moov_offset != -1) { From patchwork Sat Feb 6 17:22:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 25461 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 C652D4499D5 for ; Sat, 6 Feb 2021 19:24:08 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 936BD6898D2; Sat, 6 Feb 2021 19:24:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe06-3.mx.upcmail.net (vie01a-dmta-pe06-3.mx.upcmail.net [84.116.36.16]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8B0176880FF for ; Sat, 6 Feb 2021 19:24:01 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1l8RJR-000AOk-0B for ffmpeg-devel@ffmpeg.org; Sat, 06 Feb 2021 18:24:01 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 8RITl1qTlljeH8RITl7eho; Sat, 06 Feb 2021 18:23:01 +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=EYIcXbVYE2Qz3ZaiImwA: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:55 +0100 Message-Id: <20210206172301.11769-2-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: MS4wfL4Kw8OQfGnn6YO5T+gHxIM1G8Vh3+IvqRvjJ8oOJ3ERhHRRr5qekVFEc6DfTnEB8XlEe28Zcw3gkwbNURKCPILgh5ZJX9J8lHotsKaSzW9QpU0iyXIC VNetsqAL+e0pD/dmUgV9DS6ApACCV0zQvhhofXvmOENeFXDhr16rXkt1 Subject: [FFmpeg-devel] [PATCH 2/8] avformat/mov: Support size = 1 and size = 0 special cases in 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 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavformat/mov.c b/libavformat/mov.c index 9406e42f49..70f76caff5 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7113,6 +7113,11 @@ static int mov_probe(const AVProbeData *p) 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); + } else if (size == 0) { + size = p->buf_size - offset; + } tag = AV_RL32(p->buf + offset + 4); switch(tag) { /* check for obvious tags */ From patchwork Sat Feb 6 17:22:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 25464 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 4DABF4499D5 for ; Sat, 6 Feb 2021 19:24:12 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 16345689ADA; Sat, 6 Feb 2021 19:24:12 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-2.mx.upcmail.net (vie01a-dmta-pe05-2.mx.upcmail.net [84.116.36.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3D7AC680352 for ; Sat, 6 Feb 2021 19:24:03 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe05.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1l8RJS-000ARn-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 8RITl1qU2ljeH8RITl7eht; 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=HgDY4szC7ibxT7e2uXQA: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:56 +0100 Message-Id: <20210206172301.11769-3-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 3/8] avformat/mov: simplify size code in probing a bit 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 | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 70f76caff5..8504e97831 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7127,10 +7127,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 && - (size != 1 || - offset + 12 > (unsigned int)p->buf_size || - AV_RB64(p->buf+offset + 8) == 0)) { + if (size < 8) { score = FFMAX(score, AVPROBE_SCORE_EXTENSION); } else if (tag == MKTAG('f','t','y','p') && ( AV_RL32(p->buf + offset + 8) == MKTAG('j','p','2',' ') From patchwork Sat Feb 6 17:22:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 25467 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 3262B4499D5 for ; Sat, 6 Feb 2021 19:24:15 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 13A83689F27; Sat, 6 Feb 2021 19:24:15 +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 18C53689ADA 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-0003YM-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 8RIUl1qUIljeH8RIUl7ehx; 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=80cQ-BbwhNty8D6qCwsA: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:57 +0100 Message-Id: <20210206172301.11769-4-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 4/8] avformat/mov: Factor offset advancement out in 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 | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 8504e97831..7e634c9ec3 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7137,7 +7137,6 @@ static int mov_probe(const AVProbeData *p) } else { score = AVPROBE_SCORE_MAX; } - offset = FFMAX(4, size) + offset; break; /* those are more common words, so rate then a bit less */ case MKTAG('e','d','i','w'): /* xdcam files have reverted first tags */ @@ -7146,7 +7145,6 @@ static int mov_probe(const AVProbeData *p) case MKTAG('j','u','n','k'): case MKTAG('p','i','c','t'): score = FFMAX(score, AVPROBE_SCORE_MAX - 5); - offset = FFMAX(4, size) + offset; break; case MKTAG(0x82,0x82,0x7f,0x7d): case MKTAG('s','k','i','p'): @@ -7154,11 +7152,9 @@ static int mov_probe(const AVProbeData *p) case MKTAG('p','r','f','l'): /* if we only find those cause probedata is too small at least rate them */ score = FFMAX(score, AVPROBE_SCORE_EXTENSION); - offset = FFMAX(4, size) + offset; break; - default: - offset = FFMAX(4, size) + offset; } + offset = FFMAX(4, size) + offset; } if (score > AVPROBE_SCORE_MAX - 50 && moov_offset != -1) { /* moov atom in the header - we should make sure that this is not a 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 From patchwork Sat Feb 6 17:22:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 25462 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 D013C4499D5 for ; Sat, 6 Feb 2021 19:24:09 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B64D2689207; Sat, 6 Feb 2021 19:24:09 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe06-3.mx.upcmail.net (vie01a-dmta-pe06-3.mx.upcmail.net [84.116.36.16]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 43949688158 for ; Sat, 6 Feb 2021 19:24:02 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe06.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1l8RJS-000AOm-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 8RIUl1qUoljeH8RIUl7ei9; 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=oPqHySetpCYRlYuIN8IA: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:59 +0100 Message-Id: <20210206172301.11769-6-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 6/8] avformat/mov: Simplify probe offset handling 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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index c945586c29..5440078459 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7103,7 +7103,7 @@ static int mov_probe(const AVProbeData *p) int64_t offset; uint32_t tag; int score = 0; - int moov_offset = -1; + int moov_offset = 0; /* check file header */ offset = 0; @@ -7160,7 +7160,7 @@ static int mov_probe(const AVProbeData *p) } offset += size; } - if (score > AVPROBE_SCORE_MAX - 50 && moov_offset != -1) { + 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 */ offset = moov_offset; From patchwork Sat Feb 6 17:23:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 25463 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 D7C004499D5 for ; Sat, 6 Feb 2021 19:24:10 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id BCA8C689BC9; Sat, 6 Feb 2021 19:24:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-2.mx.upcmail.net (vie01a-dmta-pe05-2.mx.upcmail.net [84.116.36.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 429B8688158 for ; Sat, 6 Feb 2021 19:24:03 +0200 (EET) Received: from [172.31.216.235] (helo=vie01a-pemc-psmtp-pe12.mail.upcmail.net) by vie01a-dmta-pe05.mx.upcmail.net with esmtp (Exim 4.92) (envelope-from ) id 1l8RJS-0000NL-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 8RIUl1qVEljeH8RIUl7eiE; 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=_0WgcoH9PyWqEVNQNC8A: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:00 +0100 Message-Id: <20210206172301.11769-7-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 7/8] avformat/mov: Disallow a single unspecified size tag on 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" This avoids accepting bizare constructs like a mdat at position 0 and size 0 Signed-off-by: Michael Niedermayer --- libavformat/mov.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/mov.c b/libavformat/mov.c index 5440078459..2df6762ec9 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -7117,7 +7117,7 @@ static int mov_probe(const AVProbeData *p) if (size == 1 && offset + 16 > (unsigned int)p->buf_size) { size = AV_RB64(p->buf+offset + 8); minsize = 16; - } else if (size == 0) { + } else if (size == 0 && offset) { size = p->buf_size - offset; } if (size < minsize) { 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 */