summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2005-01-17 15:34:43 +0000
committerBjörn Stenberg <bjorn@haxx.se>2005-01-17 15:34:43 +0000
commitc985fa0e52a57d6d5142afeed49250e5424db87c (patch)
tree3598632a404d0cb3ce978eacc1ecd3f8b8158344
parente24a528499f992a8a8987432d0fcb3e595f1206f (diff)
downloadrockbox-c985fa0e52a57d6d5142afeed49250e5424db87c.tar.gz
rockbox-c985fa0e52a57d6d5142afeed49250e5424db87c.zip
Added some consistency checks
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5583 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/dbtree.c34
1 files changed, 32 insertions, 2 deletions
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);