diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-28 16:17:24 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-28 16:17:24 +0000 |
commit | 96a06b20671b6acd71eacea68bb7baf4054763c3 (patch) | |
tree | c09344ec4c893db22d4cec180aceb32e9eb4c72f | |
parent | c81523f62128b4b028e45586ec66f31792e4f923 (diff) | |
download | libextractor-96a06b20671b6acd71eacea68bb7baf4054763c3.tar.gz libextractor-96a06b20671b6acd71eacea68bb7baf4054763c3.zip |
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.
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | src/plugins/mp3_extractor.c | 17 |
3 files changed, 20 insertions, 1 deletions
@@ -57,6 +57,7 @@ Ronan MELENNEC <ronan.melennec@cena.fr> | |||
57 | Vasil Dimov <vd@freebsd.org> | 57 | Vasil Dimov <vd@freebsd.org> |
58 | Pavol Rusnak <prusnak@suse.cz> | 58 | Pavol Rusnak <prusnak@suse.cz> |
59 | Vidyut Samanta <vids@cs.ucla.edu> | 59 | Vidyut Samanta <vids@cs.ucla.edu> |
60 | LRN | ||
60 | 61 | ||
61 | Translations: | 62 | Translations: |
62 | German - Karl Eichwalder <ke@gnu.franken.de> | 63 | German - Karl Eichwalder <ke@gnu.franken.de> |
@@ -1,3 +1,6 @@ | |||
1 | Mon Nov 28 17:16:16 CET 2011 | ||
2 | Reduce false-positives in MP3 extractor file format detection. -LRN | ||
3 | |||
1 | Mon Nov 28 17:15:59 CET 2011 | 4 | Mon Nov 28 17:15:59 CET 2011 |
2 | Improved winsock2 detection. -LRN | 5 | Improved winsock2 detection. -LRN |
3 | 6 | ||
diff --git a/src/plugins/mp3_extractor.c b/src/plugins/mp3_extractor.c index 778c892..3d8d48d 100644 --- a/src/plugins/mp3_extractor.c +++ b/src/plugins/mp3_extractor.c | |||
@@ -207,6 +207,21 @@ EXTRACTOR_mp3_extract (const unsigned char *data, | |||
207 | frame_size = | 207 | frame_size = |
208 | 144 * bitrate / (sample_rate ? sample_rate : 1) + | 208 | 144 * bitrate / (sample_rate ? sample_rate : 1) + |
209 | ((header >> MPA_PADDING_SHIFT) & 0x1); | 209 | ((header >> MPA_PADDING_SHIFT) & 0x1); |
210 | if (frame_size <= 0) | ||
211 | { | ||
212 | /* Technically, bitrate can be 0. However, but this particular | ||
213 | * extractor is incapable of correctly processing 0-bitrate files | ||
214 | * anyway. And bitrate == 0 might also mean that this is just a | ||
215 | * random binary sequence, which is far more likely to be true. | ||
216 | * | ||
217 | * amatus suggests to use a different algorithm and parse significant | ||
218 | * part of the file, then count the number of correct mpeg frames. | ||
219 | * If the the percentage of correct frames is below a threshold, | ||
220 | * then this is not an mpeg file at all. | ||
221 | */ | ||
222 | frames -= 1; | ||
223 | break; | ||
224 | } | ||
210 | avg_bps += bitrate / 1000; | 225 | avg_bps += bitrate / 1000; |
211 | 226 | ||
212 | pos += frame_size - 4; | 227 | pos += frame_size - 4; |
@@ -221,7 +236,7 @@ EXTRACTOR_mp3_extract (const unsigned char *data, | |||
221 | } | 236 | } |
222 | while ((header & MPA_SYNC_MASK) == MPA_SYNC_MASK); | 237 | while ((header & MPA_SYNC_MASK) == MPA_SYNC_MASK); |
223 | 238 | ||
224 | if (!frames) | 239 | if (frames < 2) |
225 | return 0; /*no valid frames */ | 240 | return 0; /*no valid frames */ |
226 | ADDR ("audio/mpeg", EXTRACTOR_METATYPE_MIMETYPE); | 241 | ADDR ("audio/mpeg", EXTRACTOR_METATYPE_MIMETYPE); |
227 | avg_bps = avg_bps / frames; | 242 | avg_bps = avg_bps / frames; |