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) {