From patchwork Fri Feb 5 19:11:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 25457 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 6711444B5B9 for ; Fri, 5 Feb 2021 21:19:06 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4872B689E50; Fri, 5 Feb 2021 21:19:06 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-1.mx.upcmail.net (vie01a-dmta-pe05-1.mx.upcmail.net [84.116.36.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9C4166882B3 for ; Fri, 5 Feb 2021 21:18:59 +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 1l86Wu-0004cf-0A for ffmpeg-devel@ffmpeg.org; Fri, 05 Feb 2021 20:12:32 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 86VwlZ3QmljeH86VwlwZrz; Fri, 05 Feb 2021 20:11:32 +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: Fri, 5 Feb 2021 20:11:30 +0100 Message-Id: <20210205191132.6027-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 X-CMAE-Envelope: MS4wfFb/XDYBQO9Zx5+cFWbUnFdc/bzDCaBVFSbTgvPC5yb7ogPT3UQQF9hF/enmWLY49+OBQlJxLXI445ur+3EKEJxpXSwgYWtGqUJLmFey8yy7PyjXanob w38/FNAKUu6E68xCEGPqASM3dyLMuaGXXGUbwF7JFByQrjsgYwOQylOG Subject: [FFmpeg-devel] [PATCH 1/3] 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 Fri Feb 5 19:11:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 25456 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 581ED44B3F5 for ; Fri, 5 Feb 2021 21:18:34 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 36C29687FFC; Fri, 5 Feb 2021 21:18:34 +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 4547C680C9A for ; Fri, 5 Feb 2021 21:18:27 +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 1l86Wv-0006ji-0Q for ffmpeg-devel@ffmpeg.org; Fri, 05 Feb 2021 20:12:33 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 86VxlZ3RMljeH86VxlwZsD; Fri, 05 Feb 2021 20:11:33 +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: Fri, 5 Feb 2021 20:11:31 +0100 Message-Id: <20210205191132.6027-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210205191132.6027-1-michael@niedermayer.cc> References: <20210205191132.6027-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfBNruSQgkLVn6fgB57kn88CRBV5NgmxaphFFt23txxa2WpDHBxBX1szJz+l1kPk2vC0YKdWW1AuYSysVS4S9wu1fBTUaYQTf2Jm8jtBxf1VVypPASFG6 U7YjgT10xqpyHg0I6LtzUxtebp28S492YcoHJlho9uhJ64NltUhpNh9m Subject: [FFmpeg-devel] [PATCH 2/3] 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 Fri Feb 5 19:11:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 25458 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 7B26244B5B9 for ; Fri, 5 Feb 2021 21:19:11 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 61C3C689F00; Fri, 5 Feb 2021 21:19:11 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from vie01a-dmta-pe05-1.mx.upcmail.net (vie01a-dmta-pe05-1.mx.upcmail.net [84.116.36.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 14AF5689AA6 for ; Fri, 5 Feb 2021 21:19:05 +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 1l86Wv-0004cf-0N for ffmpeg-devel@ffmpeg.org; Fri, 05 Feb 2021 20:12:33 +0100 Received: from localhost ([213.47.68.29]) by vie01a-pemc-psmtp-pe12.mail.upcmail.net with ESMTP id 86VxlZ3RXljeH86VxlwZsL; Fri, 05 Feb 2021 20:11:33 +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: Fri, 5 Feb 2021 20:11:32 +0100 Message-Id: <20210205191132.6027-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210205191132.6027-1-michael@niedermayer.cc> References: <20210205191132.6027-1-michael@niedermayer.cc> X-CMAE-Envelope: MS4wfBNruSQgkLVn6fgB57kn88CRBV5NgmxaphFFt23txxa2WpDHBxBX1szJz+l1kPk2vC0YKdWW1AuYSysVS4S9wu1fBTUaYQTf2Jm8jtBxf1VVypPASFG6 U7YjgT10xqpyHg0I6LtzUxtebp28S492YcoHJlho9uhJ64NltUhpNh9m Subject: [FFmpeg-devel] [PATCH 3/3] 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',' ')