summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorMagnus Holmgren <magnushol@gmail.com>2007-09-03 16:15:08 +0000
committerMagnus Holmgren <magnushol@gmail.com>2007-09-03 16:15:08 +0000
commit72fafe48b9c4a258259efc757c8f9c3b40c00b37 (patch)
tree69313e9ce8bcc1d5ff5920667a2e3ac2adc00617 /firmware
parentd64975f44b809eae23a463200cb1ce8ae884184a (diff)
downloadrockbox-72fafe48b9c4a258259efc757c8f9c3b40c00b37.tar.gz
rockbox-72fafe48b9c4a258259efc757c8f9c3b40c00b37.zip
Fix FS#7698, UTF-16 comments not read correctly. Also ignore more iTunes comments.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14594 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/id3.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/firmware/id3.c b/firmware/id3.c
index d4a906fd3e..7528d06fc5 100644
--- a/firmware/id3.c
+++ b/firmware/id3.c
@@ -504,6 +504,27 @@ static const struct tag_resolver taglist[] = {
#define TAGLIST_SIZE ((int)(sizeof(taglist) / sizeof(taglist[0])))
+/* Get the length of an ID3 string in the given encoding. Returns the length
+ * in bytes, including end nil, or -1 if the encoding is unknown.
+ */
+static int unicode_len(char encoding, const void* string)
+{
+ int len = 0;
+
+ if (encoding == 0x01 || encoding == 0x02) {
+ short* s = (short*) string;
+
+ while (*s++) {
+ }
+
+ len = (void*) s - string;
+ } else {
+ len = strlen((char*) string) + 1;
+ }
+
+ return len;
+}
+
/* Checks to see if the passed in string is a 16-bit wide Unicode v2
string. If it is, we convert it to a UTF-8 string. If it's not unicode,
we convert from the default codepage */
@@ -892,7 +913,6 @@ static void setid3v2title(int fd, struct mp3entry *entry)
char** ptag = tr->offset ? (char**) (((char*)entry) + tr->offset)
: NULL;
char* tag;
- int comm_offset=0;
/* Only ID3_VER_2_2 uses frames with three-character names. */
if (((version == ID3_VER_2_2) && (tr->tag_length != 3))
@@ -930,14 +950,15 @@ static void setid3v2title(int fd, struct mp3entry *entry)
*/
if(!memcmp( header, "COMM", 4 )) {
- /* ignore comments with iTunes 7 gapless data */
- if(!strcmp(tag+4, "iTunNORM"))
+ int offset;
+ /* ignore comments with iTunes 7 soundcheck/gapless data */
+ if(!strcmp(tag+4, "iTun"))
break;
- comm_offset = 3 + strlen(tag+4) + 1;
- if(bytesread>comm_offset) {
- bytesread-=comm_offset;
- memmove(tag+1, tag+comm_offset+1, bytesread-1);
- }
+ offset = 3 + unicode_len(*tag, tag + 4);
+ if(bytesread > offset) {
+ bytesread -= offset;
+ memmove(tag + 1, tag + 1 + offset, bytesread - 1);
+ }
}
/* Attempt to parse Unicode string only if the tag contents