Mercurial > audlegacy-plugins
comparison src/madplug/plugin.c @ 2667:84d34cd6aa71
Experimental changes in MADPlug's probing function to lessen chance of misdetection
(some arbitrary files, such as old 15-inst ST MODs were being probed as MP3
streams.) NOTICE! A debug print is temporarily left in to see if any real MP3
files get rejected.
| author | Matti Hamalainen <ccr@tnsp.org> |
|---|---|
| date | Fri, 30 May 2008 06:09:16 +0300 |
| parents | bd3a24b39058 |
| children | 45be141b7586 |
comparison
equal
deleted
inserted
replaced
| 2666:053341c248ef | 2667:84d34cd6aa71 |
|---|---|
| 252 static int | 252 static int |
| 253 audmad_is_our_fd(char *filename, VFSFile *fin) | 253 audmad_is_our_fd(char *filename, VFSFile *fin) |
| 254 { | 254 { |
| 255 guint32 check; | 255 guint32 check; |
| 256 gchar *ext = extname(filename); | 256 gchar *ext = extname(filename); |
| 257 gint cyc = 0, chkcount = 0, chksize = 4096; | |
| 258 guchar buf[4]; | 257 guchar buf[4]; |
| 259 guchar tmp[4096]; | |
| 260 gint ret, i, frameSize; | |
| 261 | 258 |
| 262 info.remote = aud_vfs_is_remote(filename); | 259 info.remote = aud_vfs_is_remote(filename); |
| 263 | 260 |
| 264 /* I've seen some flac files beginning with id3 frames.. | 261 /* I've seen some flac files beginning with id3 frames.. |
| 265 so let's exclude known non-mp3 filename extensions */ | 262 so let's exclude known non-mp3 filename extensions */ |
| 269 !strcasecmp("wma", ext) ) | 266 !strcasecmp("wma", ext) ) |
| 270 ) | 267 ) |
| 271 return 0; | 268 return 0; |
| 272 | 269 |
| 273 if (fin == NULL) { | 270 if (fin == NULL) { |
| 274 g_message("fin = NULL"); | 271 g_message("fin = NULL for %s", filename); |
| 275 return 0; | 272 return 0; |
| 276 } | 273 } |
| 277 | 274 |
| 278 if(aud_vfs_fread(buf, 1, 4, fin) == 0) { | 275 if (aud_vfs_fread(buf, 1, 4, fin) == 0) { |
| 279 gchar *tmp = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); | 276 g_message("aud_vfs_fread failed @1 %s", filename); |
| 280 g_message("aud_vfs_fread failed @1 %s", tmp); | |
| 281 g_free(tmp); | |
| 282 return 0; | 277 return 0; |
| 283 } | 278 } |
| 284 | 279 |
| 285 check = mp3_head_convert(buf); | 280 check = mp3_head_convert(buf); |
| 286 | 281 |
| 290 return 0; | 285 return 0; |
| 291 else if (memcmp(buf, "RIFF", 4) == 0) | 286 else if (memcmp(buf, "RIFF", 4) == 0) |
| 292 { | 287 { |
| 293 aud_vfs_fseek(fin, 4, SEEK_CUR); | 288 aud_vfs_fseek(fin, 4, SEEK_CUR); |
| 294 if(aud_vfs_fread(buf, 1, 4, fin) == 0) { | 289 if(aud_vfs_fread(buf, 1, 4, fin) == 0) { |
| 295 gchar *tmp = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); | 290 g_message("aud_vfs_fread failed @2 %s", filename); |
| 296 g_message("aud_vfs_fread failed @2 %s", tmp); | |
| 297 g_free(tmp); | |
| 298 return 0; | 291 return 0; |
| 299 } | 292 } |
| 300 | 293 |
| 301 if (memcmp(buf, "RMP3", 4) == 0) | 294 if (memcmp(buf, "RMP3", 4) == 0) |
| 302 return 1; | 295 return 1; |
| 303 } | 296 } |
| 304 | 297 |
| 305 // check data for frame header | 298 /* Check stream data for frame header(s) |
| 306 while (!mp3_head_check(check, &frameSize)) | 299 */ |
| 300 guchar chkbuf[2048]; | |
| 301 gint chkret, i, framesize, cyc, chkcount, chksize = sizeof(chkbuf); | |
| 302 | |
| 303 for (cyc = chkcount = 0; cyc < 32; cyc++) | |
| 307 { | 304 { |
| 308 if((ret = aud_vfs_fread(tmp, 1, chksize, fin)) == 0){ | 305 if ((chkret = aud_vfs_fread(chkbuf, 1, chksize, fin)) == 0) |
| 309 gchar *tmp = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); | 306 break; |
| 310 g_message("aud_vfs_fread failed @3 %s", tmp); | 307 |
| 311 g_free(tmp); | 308 for (i = 0; i < chkret; i++) |
| 312 return 0; | |
| 313 } | |
| 314 for (i = 0; i < ret; i++) | |
| 315 { | 309 { |
| 316 check <<= 8; | 310 check <<= 8; |
| 317 check |= tmp[i]; | 311 check |= chkbuf[i]; |
| 318 | 312 |
| 319 if (mp3_head_check(check, &frameSize)) { | 313 if (mp3_head_check(check, &framesize)) { |
| 320 /* when the first matching frame header is found, we check for | 314 /* when the first matching frame header is found, we check for |
| 321 * another frame by seeking to the approximate start of the | 315 * another frame by seeking to the approximate start of the |
| 322 * next header ... also reduce the check size. | 316 * next header ... also reduce the check size. |
| 323 */ | 317 */ |
| 324 if (++chkcount >= 3) return 1; | 318 if (++chkcount >= 4) return 1; |
| 325 aud_vfs_fseek(fin, frameSize-4, SEEK_CUR); | 319 aud_vfs_fseek(fin, framesize-8, SEEK_CUR); |
| 326 check = 0; | 320 check = 0; |
| 327 chksize = 8; | 321 chksize = 16; |
| 322 } else { | |
| 323 aud_vfs_fseek(fin, chksize, SEEK_CUR); | |
| 328 } | 324 } |
| 329 } | 325 } |
| 330 | 326 } |
| 331 if (++cyc > 32) | 327 |
| 332 return 0; | 328 g_message("Rejecting %s (not an MP3 file?)", filename); |
| 333 } | 329 return 0; |
| 334 | |
| 335 return 1; | |
| 336 } | 330 } |
| 337 | 331 |
| 338 // audacious vfs version | 332 // audacious vfs version |
| 339 static int | 333 static int |
| 340 audmad_is_our_file(char *filename) | 334 audmad_is_our_file(char *filename) |
