mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-10-14 02:27:39 -04:00
Added some consistency checks
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5583 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
e24a528499
commit
c985fa0e52
1 changed files with 32 additions and 2 deletions
|
@ -47,6 +47,8 @@
|
||||||
#define BE32(_x_) _x_
|
#define BE32(_x_) _x_
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define ID3DB_VERSION 1
|
||||||
|
|
||||||
static int fd;
|
static int fd;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -54,12 +56,13 @@ static int
|
||||||
songcount, albumcount, artistcount,
|
songcount, albumcount, artistcount,
|
||||||
songlen, songarraylen,
|
songlen, songarraylen,
|
||||||
albumlen, albumarraylen,
|
albumlen, albumarraylen,
|
||||||
artistlen;
|
artistlen, initialized = 0;
|
||||||
|
|
||||||
int db_init(void)
|
int db_init(void)
|
||||||
{
|
{
|
||||||
unsigned int version;
|
unsigned int version;
|
||||||
unsigned int buf[12];
|
unsigned int buf[12];
|
||||||
|
unsigned char* ptr = (char*)buf;
|
||||||
|
|
||||||
fd = open(ROCKBOX_DIR "/rockbox.id3db", O_RDONLY);
|
fd = open(ROCKBOX_DIR "/rockbox.id3db", O_RDONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
|
@ -68,7 +71,20 @@ int db_init(void)
|
||||||
}
|
}
|
||||||
read(fd, buf, 48);
|
read(fd, buf, 48);
|
||||||
|
|
||||||
|
if (ptr[0] != 'R' ||
|
||||||
|
ptr[1] != 'D' ||
|
||||||
|
ptr[2] != 'B')
|
||||||
|
{
|
||||||
|
DEBUGF("File is not a rockbox id3 database, aborting\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
version = BE32(buf[0]) & 0xff;
|
version = BE32(buf[0]) & 0xff;
|
||||||
|
if (version != ID3DB_VERSION)
|
||||||
|
{
|
||||||
|
DEBUGF("Unsupported database version %d, aborting.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
DEBUGF("Version: RDB%d\n", version);
|
DEBUGF("Version: RDB%d\n", version);
|
||||||
|
|
||||||
songstart = BE32(buf[1]);
|
songstart = BE32(buf[1]);
|
||||||
|
@ -93,7 +109,15 @@ int db_init(void)
|
||||||
DEBUGF("Number of artists: %d\n", artistcount);
|
DEBUGF("Number of artists: %d\n", artistcount);
|
||||||
DEBUGF("Artiststart: %x\n", artiststart);
|
DEBUGF("Artiststart: %x\n", artiststart);
|
||||||
DEBUGF("Artistlen: %d\n", artistlen);
|
DEBUGF("Artistlen: %d\n", artistlen);
|
||||||
|
|
||||||
|
if (songstart > albumstart ||
|
||||||
|
albumstart > artiststart)
|
||||||
|
{
|
||||||
|
DEBUGF("Corrupt id3db database, aborting.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
initialized = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,6 +132,12 @@ int db_load(struct tree_context* c, bool* dir_buffer_full)
|
||||||
|
|
||||||
int table = c->currtable;
|
int table = c->currtable;
|
||||||
int extra = c->currextra;
|
int extra = c->currextra;
|
||||||
|
|
||||||
|
if (!initialized) {
|
||||||
|
DEBUGF("ID3 database is not initialized.\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
c->dentry_size = 2 * sizeof(int);
|
c->dentry_size = 2 * sizeof(int);
|
||||||
|
|
||||||
DEBUGF("db_load(%d, %x)\n", table, extra);
|
DEBUGF("db_load(%d, %x)\n", table, extra);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue