OSDN Git Service

ID3v1 tag's strings are ISO8859, not UTF-8, so do the proper conversion when extracti...
authorAndreas Huber <andih@google.com>
Mon, 8 Feb 2010 19:04:56 +0000 (11:04 -0800)
committerAndreas Huber <andih@google.com>
Tue, 9 Feb 2010 00:46:27 +0000 (16:46 -0800)
related-to-bug: 2399408

media/libstagefright/id3/ID3.cpp

index 65a4ae4..e022bb0 100644 (file)
@@ -274,7 +274,9 @@ static void convertISO8859ToString8(
         String8 *s) {
     size_t utf8len = 0;
     for (size_t i = 0; i < size; ++i) {
-        if (data[i] < 0x80) {
+        if (data[i] == '\0') {
+            break;
+        } else if (data[i] < 0x80) {
             ++utf8len;
         } else {
             utf8len += 2;
@@ -291,7 +293,9 @@ static void convertISO8859ToString8(
     char *tmp = new char[utf8len];
     char *ptr = tmp;
     for (size_t i = 0; i < size; ++i) {
-        if (data[i] < 0x80) {
+        if (data[i] == '\0') {
+            break;
+        } else if (data[i] < 0x80) {
             *ptr++ = data[i];
         } else if (data[i] < 0xc0) {
             *ptr++ = 0xc2;
@@ -325,7 +329,7 @@ void ID3::Iterator::getString(String8 *id) const {
             return;
         }
 
-        id->setTo((const char *)mFrameData, mFrameSize);
+        convertISO8859ToString8(mFrameData, mFrameSize, id);
         return;
     }