diff mbox series

[FFmpeg-devel,5/8] avformat/mov: Ignore tags with invalid size during probing

Message ID 20210206172301.11769-5-michael@niedermayer.cc
State Accepted
Commit 0b78016b2d7c36b32d07669c0c86bc4b4225ec98
Headers show
Series [FFmpeg-devel,1/8] avformat/mov: factor size out of probe code | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Michael Niedermayer Feb. 6, 2021, 5:22 p.m. UTC
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/mov.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

Comments

Paul B Mahol Feb. 6, 2021, 10:08 p.m. UTC | #1
LGTM
diff mbox series

Patch

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