gst/typefind/gsttypefindfunctions.c: Improve FLAC-without-headers typefinding by...
authorSebastian Dröge <slomo@circular-chaos.org>
Mon, 13 Oct 2008 07:52:41 +0000 (07:52 +0000)
committerSebastian Dröge <slomo@circular-chaos.org>
Mon, 13 Oct 2008 07:52:41 +0000 (07:52 +0000)
Original commit message from CVS:
* gst/typefind/gsttypefindfunctions.c: (flac_type_find):
Improve FLAC-without-headers typefinding by looking at most of the
frame header and checking if invalid values are used. Should prevent
quite some false positives compared to the old version which only
check if the first 14 bits are set.

ChangeLog
gst/typefind/gsttypefindfunctions.c

index e360c90..b77c967 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-10-13  Sebastian Dröge  <sebastian.droege@collabora.co.uk>
+
+       * gst/typefind/gsttypefindfunctions.c: (flac_type_find):
+       Improve FLAC-without-headers typefinding by looking at most of the
+       frame header and checking if invalid values are used. Should prevent
+       quite some false positives compared to the old version which only
+       check if the first 14 bits are set.
+
 2008-10-11  Stefan Kost  <ensonic@users.sf.net>
 
        * sys/xvimage/xvimagesink.c:
index 90ee1ae..a02981f 100644 (file)
@@ -541,13 +541,35 @@ flac_type_find (GstTypeFind * tf, gpointer unused)
   /* flac without headers */
   /* 64K should be enough */
   while (c.offset < (64 * 1024)) {
-    if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 2)))
+    if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 3)))
       break;
 
     if (data[0] == 0xff && (data[1] >> 2) == 0x3e) {
+      /* bit 15 must be 0 */
+      if (((data[1] >> 1) & 0x01) == 0x01)
+        continue;
+
+      /* blocksize must be != 0x00 */
+      if ((data[2] >> 4) == 0x00)
+        continue;
+
+      /* samplerate must be != 0x0f */
+      if ((data[2] & 0x0f) == 0x0f)
+        continue;
+
+      /* channel assignment must be < 11 */
+      if ((data[3] >> 4) >= 11)
+        continue;
+
+      /* sample size must be != 0x07 */
+      if (((data[3] >> 1) & 0x07) == 0x07)
+        continue;
+
+      /* next bit must be 0 */
+      if ((data[3] & 0x01) == 0x01)
+        continue;
+
       gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, FLAC_CAPS);
-      /* TODO: maybe check more parts of the frame header 
-       * to lower the risk of false positives */
       return;
     }
     data_scan_ctx_advance (tf, &c, 1);