Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge "use utf8_length() instead of local function, isValidUtf8()"

  • Loading branch information...
commit 90577af796cd526f842d6f07c2d95ed4fcc2f6d8 2 parents 559167f + 1a8b6c2
authored android code review committed

Showing 1 changed file with 5 additions and 48 deletions. Show diff stats Hide diff stats

  1. 53  media/jni/android_media_MediaScanner.cpp
53  media/jni/android_media_MediaScanner.cpp
@@ -19,6 +19,7 @@
19 19
 #define LOG_TAG "MediaScannerJNI"
20 20
 #include <utils/Log.h>
21 21
 #include <utils/threads.h>
  22
+#include <utils/Unicode.h>
22 23
 #include <media/mediascanner.h>
23 24
 #include <media/stagefright/StagefrightMediaScanner.h>
24 25
 
@@ -56,53 +57,6 @@ static status_t checkAndClearExceptionFromCallback(JNIEnv* env, const char* meth
56 57
     return OK;
57 58
 }
58 59
 
59  
-// stolen from dalvik/vm/checkJni.cpp
60  
-static bool isValidUtf8(const char* bytes) {
61  
-    while (*bytes != '\0') {
62  
-        unsigned char utf8 = *(bytes++);
63  
-        // Switch on the high four bits.
64  
-        switch (utf8 >> 4) {
65  
-        case 0x00:
66  
-        case 0x01:
67  
-        case 0x02:
68  
-        case 0x03:
69  
-        case 0x04:
70  
-        case 0x05:
71  
-        case 0x06:
72  
-        case 0x07:
73  
-            // Bit pattern 0xxx. No need for any extra bytes.
74  
-            break;
75  
-        case 0x08:
76  
-        case 0x09:
77  
-        case 0x0a:
78  
-        case 0x0b:
79  
-        case 0x0f:
80  
-            /*
81  
-             * Bit pattern 10xx or 1111, which are illegal start bytes.
82  
-             * Note: 1111 is valid for normal UTF-8, but not the
83  
-             * modified UTF-8 used here.
84  
-             */
85  
-            return false;
86  
-        case 0x0e:
87  
-            // Bit pattern 1110, so there are two additional bytes.
88  
-            utf8 = *(bytes++);
89  
-            if ((utf8 & 0xc0) != 0x80) {
90  
-                return false;
91  
-            }
92  
-            // Fall through to take care of the final byte.
93  
-        case 0x0c:
94  
-        case 0x0d:
95  
-            // Bit pattern 110x, so there is one additional byte.
96  
-            utf8 = *(bytes++);
97  
-            if ((utf8 & 0xc0) != 0x80) {
98  
-                return false;
99  
-            }
100  
-            break;
101  
-        }
102  
-    }
103  
-    return true;
104  
-}
105  
-
106 60
 class MyMediaScannerClient : public MediaScannerClient
107 61
 {
108 62
 public:
@@ -170,8 +124,11 @@ class MyMediaScannerClient : public MediaScannerClient
170 124
             mEnv->ExceptionClear();
171 125
             return NO_MEMORY;
172 126
         }
  127
+
  128
+        // Check if the value is valid UTF-8 string and replace
  129
+        // any un-printable characters with '?' when it's not.
173 130
         char *cleaned = NULL;
174  
-        if (!isValidUtf8(value)) {
  131
+        if (utf8_length(value) == -1) {
175 132
             cleaned = strdup(value);
176 133
             char *chp = cleaned;
177 134
             char ch;

0 notes on commit 90577af

Please sign in to comment.
Something went wrong with that request. Please try again.