Index: base/android/jni_string.cc |
diff --git a/base/android/jni_string.cc b/base/android/jni_string.cc |
index 3f3ba826d6d7f2d02f4da3edf06ef8a7fd63c16b..26e7114fd60e8f74f118e21187e2ba7e008501a5 100644 |
--- a/base/android/jni_string.cc |
+++ b/base/android/jni_string.cc |
@@ -17,10 +17,15 @@ std::string ConvertJavaStringToUTF8(JNIEnv* env, jstring str) { |
return UTF16ToUTF8(ConvertJavaStringToUTF16(env, str)); |
} |
-jstring ConvertUTF8ToJavaString(JNIEnv* env, const std::string& str) { |
- jstring result = env->NewStringUTF(str.c_str()); |
- CheckException(env); |
- return result; |
+jstring ConvertUTF8ToJavaString(JNIEnv* env, const base::StringPiece& str) { |
+ // JNI's NewStringUTF expects "modified" UTF8 so instead create the string |
+ // via our own UTF16 conversion utility. |
+ // Further, Dalvik requires the string passed into NewStringUTF() to come from |
+ // a trusted source. We can't guarantee that all UTF8 will be sanitized before |
+ // it gets here, so constructing via UTF16 side-steps this issue. |
+ // (Dalvik stores strings internally as UTF16 anyway, so there shouldn't be |
+ // a significant performance hit by doing it this way). |
+ return ConvertUTF16ToJavaString(env, UTF8ToUTF16(str)); |
} |
string16 ConvertJavaStringToUTF16(JNIEnv* env, jstring str) { |