commit 96a06b20671b6acd71eacea68bb7baf4054763c3
parent c81523f62128b4b028e45586ec66f31792e4f923
Author: Christian Grothoff <christian@grothoff.org>
Date: Mon, 28 Nov 2011 16:17:24 +0000
Changes mp3 extractor to discard frames with frame_size <= 0.
Obviously, this is quite hacky, but:
A) Files with 0 bitrate are rare.
B) At least it won't trigger as easily on random binary data
Also, makes mp3 extractor check for at least 2 valid frames in a row.
That is, if frame size is not 0, then the next frame header after the
first one we found must also be valid, otherwise this is not
considered to be an mp3 file. This is the best i can do with such a
short and simple patch, further improvements are only possible with
something more complex, i think.
Diffstat:
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/AUTHORS b/AUTHORS
@@ -57,6 +57,7 @@ Ronan MELENNEC <ronan.melennec@cena.fr>
Vasil Dimov <vd@freebsd.org>
Pavol Rusnak <prusnak@suse.cz>
Vidyut Samanta <vids@cs.ucla.edu>
+LRN
Translations:
German - Karl Eichwalder <ke@gnu.franken.de>
diff --git a/ChangeLog b/ChangeLog
@@ -1,3 +1,6 @@
+Mon Nov 28 17:16:16 CET 2011
+ Reduce false-positives in MP3 extractor file format detection. -LRN
+
Mon Nov 28 17:15:59 CET 2011
Improved winsock2 detection. -LRN
diff --git a/src/plugins/mp3_extractor.c b/src/plugins/mp3_extractor.c
@@ -207,6 +207,21 @@ EXTRACTOR_mp3_extract (const unsigned char *data,
frame_size =
144 * bitrate / (sample_rate ? sample_rate : 1) +
((header >> MPA_PADDING_SHIFT) & 0x1);
+ if (frame_size <= 0)
+ {
+ /* Technically, bitrate can be 0. However, but this particular
+ * extractor is incapable of correctly processing 0-bitrate files
+ * anyway. And bitrate == 0 might also mean that this is just a
+ * random binary sequence, which is far more likely to be true.
+ *
+ * amatus suggests to use a different algorithm and parse significant
+ * part of the file, then count the number of correct mpeg frames.
+ * If the the percentage of correct frames is below a threshold,
+ * then this is not an mpeg file at all.
+ */
+ frames -= 1;
+ break;
+ }
avg_bps += bitrate / 1000;
pos += frame_size - 4;
@@ -221,7 +236,7 @@ EXTRACTOR_mp3_extract (const unsigned char *data,
}
while ((header & MPA_SYNC_MASK) == MPA_SYNC_MASK);
- if (!frames)
+ if (frames < 2)
return 0; /*no valid frames */
ADDR ("audio/mpeg", EXTRACTOR_METATYPE_MIMETYPE);
avg_bps = avg_bps / frames;