Browse code

Add more sanity checks for header elements, rejecting files with clearly invalid values that wouldn't play right anyway and reduce probe score to MAX/2. Passes probetest v2.

Originally committed as revision 19842 to svn://svn.ffmpeg.org/ffmpeg/trunk

Reimar Döffinger authored on 2009/09/15 04:58:51
Showing 1 changed files
... ...
@@ -42,13 +42,24 @@ typedef struct MaxisXADemuxContext {
42 42
 
43 43
 static int xa_probe(AVProbeData *p)
44 44
 {
45
+    int channels, srate, bits_per_sample;
46
+    if (p->buf_size < 24)
47
+        return 0;
45 48
     switch(AV_RL32(p->buf)) {
46 49
     case XA00_TAG:
47 50
     case XAI0_TAG:
48 51
     case XAJ0_TAG:
49
-        return AVPROBE_SCORE_MAX;
52
+        break;
53
+    default:
54
+        return 0;
50 55
     }
51
-    return 0;
56
+    channels        = AV_RL16(p->buf + 10);
57
+    srate           = AV_RL32(p->buf + 12);
58
+    bits_per_sample = AV_RL16(p->buf + 22);
59
+    if (!channels || channels > 8 || !srate || srate > 192000 ||
60
+        bits_per_sample < 4 || bits_per_sample > 32)
61
+        return 0;
62
+    return AVPROBE_SCORE_MAX/2;
52 63
 }
53 64
 
54 65
 static int xa_read_header(AVFormatContext *s,