diff mbox series

[FFmpeg-devel,8/8] avformat/mov: Only detect things that contain a moov or mdat as mov

Message ID 20210206172301.11769-8-michael@niedermayer.cc
State New
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:23 p.m. UTC
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 <michael@niedermayer.cc>
---
 libavformat/mov.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
diff mbox series

Patch

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 */