FS#11828: Fix in core mod parser to blindly accept any .mod you throw at it. Based on MikMod.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29105 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
52c6789450
commit
01586b5ffe
1 changed files with 52 additions and 10 deletions
|
@ -19,40 +19,82 @@
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include "system.h"
|
#include "system.h"
|
||||||
#include "metadata.h"
|
#include "metadata.h"
|
||||||
|
#include <string-extra.h>
|
||||||
#include "metadata_common.h"
|
#include "metadata_common.h"
|
||||||
#include "metadata_parsers.h"
|
#include "metadata_parsers.h"
|
||||||
#include "rbunicode.h"
|
#include "rbunicode.h"
|
||||||
|
|
||||||
|
#define MODULEHEADERSIZE 0x438
|
||||||
|
|
||||||
bool get_mod_metadata(int fd, struct mp3entry* id3)
|
bool get_mod_metadata(int fd, struct mp3entry* id3)
|
||||||
{
|
{
|
||||||
/* Use the trackname part of the id3 structure as a temporary buffer */
|
/* Use the trackname part of the id3 structure as a temporary buffer */
|
||||||
unsigned char buf[1084];
|
unsigned char buf[MODULEHEADERSIZE];
|
||||||
int read_bytes;
|
unsigned char id[4];
|
||||||
|
bool is_mod_file = false;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
|
|
||||||
if ((lseek(fd, 0, SEEK_SET) < 0)
|
if ((lseek(fd, 0, SEEK_SET) < 0)
|
||||||
|| ((read_bytes = read(fd, buf, sizeof(buf))) < 1084))
|
|| (read(fd, buf, sizeof(buf)) < MODULEHEADERSIZE))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We don't do file format checking here
|
if (read(fd, id, sizeof(id)) < (ssize_t)sizeof(id))
|
||||||
* There can be .mod files without any signatures out there */
|
return false;
|
||||||
|
|
||||||
|
/* Mod type checking based on MikMod */
|
||||||
|
/* Protracker and variants */
|
||||||
|
if ((!memcmp(id, "M.K.", 4)) || (!memcmp(id, "M!K!", 4))) {
|
||||||
|
is_mod_file = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Star Tracker */
|
||||||
|
if (((!memcmp(id, "FLT", 3)) || (!memcmp(id, "EXO", 3))) &&
|
||||||
|
(isdigit(id[3]))) {
|
||||||
|
char numchn = id[3] - '0';
|
||||||
|
if (numchn == 4 || numchn == 8)
|
||||||
|
is_mod_file = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Oktalyzer (Amiga) */
|
||||||
|
if (!memcmp(id, "OKTA", 4)) {
|
||||||
|
is_mod_file = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Oktalyser (Atari) */
|
||||||
|
if (!memcmp(id, "CD81", 4)) {
|
||||||
|
is_mod_file = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fasttracker */
|
||||||
|
if ((!memcmp(id + 1, "CHN", 3)) && (isdigit(id[0]))) {
|
||||||
|
is_mod_file = true;
|
||||||
|
}
|
||||||
|
/* Fasttracker or Taketracker */
|
||||||
|
if (((!memcmp(id + 2, "CH", 2)) || (!memcmp(id + 2, "CN", 2)))
|
||||||
|
&& (isdigit(id[0])) && (isdigit(id[1]))) {
|
||||||
|
is_mod_file = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Don't try to play if we can't find a known mod type
|
||||||
|
* (there are mod files which have nothing to do with music) */
|
||||||
|
if (!is_mod_file)
|
||||||
|
return false;
|
||||||
|
|
||||||
p = id3->id3v2buf;
|
p = id3->id3v2buf;
|
||||||
|
|
||||||
/* Copy Title */
|
/* Copy Title */
|
||||||
strcpy(p, &buf[0x00]);
|
if (strlcpy(p, buf, sizeof(id3->id3v2buf)) >= sizeof(id3->id3v2buf))
|
||||||
|
return false;
|
||||||
|
|
||||||
id3->title = p;
|
id3->title = p;
|
||||||
p += strlen(p)+1;
|
|
||||||
|
|
||||||
id3->bitrate = filesize(fd)/1024; /* size in kb */
|
id3->bitrate = filesize(fd)/1024; /* size in kb */
|
||||||
id3->frequency = 44100;
|
id3->frequency = 44100;
|
||||||
|
|
Loading…
Reference in a new issue