From c985fa0e52a57d6d5142afeed49250e5424db87c Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Mon, 17 Jan 2005 15:34:43 +0000 Subject: Added some consistency checks git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5583 a1c6a512-1295-4272-9138-f99709370657 --- apps/dbtree.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'apps') diff --git a/apps/dbtree.c b/apps/dbtree.c index f9bd950057..e46776f1c2 100644 --- a/apps/dbtree.c +++ b/apps/dbtree.c @@ -47,6 +47,8 @@ #define BE32(_x_) _x_ #endif +#define ID3DB_VERSION 1 + static int fd; static int @@ -54,12 +56,13 @@ static int songcount, albumcount, artistcount, songlen, songarraylen, albumlen, albumarraylen, - artistlen; + artistlen, initialized = 0; int db_init(void) { unsigned int version; unsigned int buf[12]; + unsigned char* ptr = (char*)buf; fd = open(ROCKBOX_DIR "/rockbox.id3db", O_RDONLY); if (fd < 0) { @@ -68,7 +71,20 @@ int db_init(void) } 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; + if (version != ID3DB_VERSION) + { + DEBUGF("Unsupported database version %d, aborting.\n"); + return -1; + } DEBUGF("Version: RDB%d\n", version); songstart = BE32(buf[1]); @@ -93,7 +109,15 @@ int db_init(void) DEBUGF("Number of artists: %d\n", artistcount); DEBUGF("Artiststart: %x\n", artiststart); DEBUGF("Artistlen: %d\n", artistlen); - + + if (songstart > albumstart || + albumstart > artiststart) + { + DEBUGF("Corrupt id3db database, aborting.\n"); + return -1; + } + + initialized = 1; return 0; } @@ -108,6 +132,12 @@ int db_load(struct tree_context* c, bool* dir_buffer_full) int table = c->currtable; int extra = c->currextra; + + if (!initialized) { + DEBUGF("ID3 database is not initialized.\n"); + return 0; + } + c->dentry_size = 2 * sizeof(int); DEBUGF("db_load(%d, %x)\n", table, extra); -- cgit v1.2.3