summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-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 @@
47#define BE32(_x_) _x_ 47#define BE32(_x_) _x_
48#endif 48#endif
49 49
50#define ID3DB_VERSION 1
51
50static int fd; 52static int fd;
51 53
52static int 54static int
@@ -54,12 +56,13 @@ static int
54 songcount, albumcount, artistcount, 56 songcount, albumcount, artistcount,
55 songlen, songarraylen, 57 songlen, songarraylen,
56 albumlen, albumarraylen, 58 albumlen, albumarraylen,
57 artistlen; 59 artistlen, initialized = 0;
58 60
59int db_init(void) 61int db_init(void)
60{ 62{
61 unsigned int version; 63 unsigned int version;
62 unsigned int buf[12]; 64 unsigned int buf[12];
65 unsigned char* ptr = (char*)buf;
63 66
64 fd = open(ROCKBOX_DIR "/rockbox.id3db", O_RDONLY); 67 fd = open(ROCKBOX_DIR "/rockbox.id3db", O_RDONLY);
65 if (fd < 0) { 68 if (fd < 0) {
@@ -68,7 +71,20 @@ int db_init(void)
68 } 71 }
69 read(fd, buf, 48); 72 read(fd, buf, 48);
70 73
74 if (ptr[0] != 'R' ||
75 ptr[1] != 'D' ||
76 ptr[2] != 'B')
77 {
78 DEBUGF("File is not a rockbox id3 database, aborting\n");
79 return -1;
80 }
81
71 version = BE32(buf[0]) & 0xff; 82 version = BE32(buf[0]) & 0xff;
83 if (version != ID3DB_VERSION)
84 {
85 DEBUGF("Unsupported database version %d, aborting.\n");
86 return -1;
87 }
72 DEBUGF("Version: RDB%d\n", version); 88 DEBUGF("Version: RDB%d\n", version);
73 89
74 songstart = BE32(buf[1]); 90 songstart = BE32(buf[1]);
@@ -93,7 +109,15 @@ int db_init(void)
93 DEBUGF("Number of artists: %d\n", artistcount); 109 DEBUGF("Number of artists: %d\n", artistcount);
94 DEBUGF("Artiststart: %x\n", artiststart); 110 DEBUGF("Artiststart: %x\n", artiststart);
95 DEBUGF("Artistlen: %d\n", artistlen); 111 DEBUGF("Artistlen: %d\n", artistlen);
96 112
113 if (songstart > albumstart ||
114 albumstart > artiststart)
115 {
116 DEBUGF("Corrupt id3db database, aborting.\n");
117 return -1;
118 }
119
120 initialized = 1;
97 return 0; 121 return 0;
98} 122}
99 123
@@ -108,6 +132,12 @@ int db_load(struct tree_context* c, bool* dir_buffer_full)
108 132
109 int table = c->currtable; 133 int table = c->currtable;
110 int extra = c->currextra; 134 int extra = c->currextra;
135
136 if (!initialized) {
137 DEBUGF("ID3 database is not initialized.\n");
138 return 0;
139 }
140
111 c->dentry_size = 2 * sizeof(int); 141 c->dentry_size = 2 * sizeof(int);
112 142
113 DEBUGF("db_load(%d, %x)\n", table, extra); 143 DEBUGF("db_load(%d, %x)\n", table, extra);