From d415303c4d02c1d30dd4199bade4694bf2cb4615 Mon Sep 17 00:00:00 2001 From: "tao.pei" Date: Tue, 2 Jun 2015 10:06:20 +0800 Subject: [PATCH] Pass MUTF-8 paths to open(2) instead of UTF-8. Modified UTF-8 and UTF-8 differ with respect to how they handle non-BMP characters. Modified UTF-8 uses 2 x 3 byte encodings, one each for the high and low surrogate, whereas UTF-8 uses a single 4 byte sequence. File systems don't specify and encoding and therefore the file name encoding will vary depending on how it's created. All standard Java APIs (java.io.File / FileOutputStream etc.) use Modified UTF-8 filenames, so we assume that's the status quo. We will also audit code from the rest of the platform to make sure that file names are encoded consistently. bug: 21578056 Change-Id: I8e37af7f7cc442805a48899917f8e61c8f81fba6 --- core/jni/android_os_Parcel.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/core/jni/android_os_Parcel.cpp b/core/jni/android_os_Parcel.cpp index 4f29c50274231..65eb38c452901 100644 --- a/core/jni/android_os_Parcel.cpp +++ b/core/jni/android_os_Parcel.cpp @@ -449,15 +449,11 @@ static jobject android_os_Parcel_openFileDescriptor(JNIEnv* env, jclass clazz, jniThrowNullPointerException(env, NULL); return NULL; } - const jchar* str = env->GetStringCritical(name, 0); - if (str == NULL) { - // Whatever, whatever. - jniThrowException(env, "java/lang/IllegalStateException", NULL); + ScopedUtfChars name8(env, name); + if (name8.c_str() == NULL) { return NULL; } - String8 name8(reinterpret_cast(str), - env->GetStringLength(name)); - env->ReleaseStringCritical(name, str); + int flags=0; switch (mode&0x30000000) { case 0: @@ -480,7 +476,7 @@ static jobject android_os_Parcel_openFileDescriptor(JNIEnv* env, jclass clazz, if (mode&0x00000001) realMode |= S_IROTH; if (mode&0x00000002) realMode |= S_IWOTH; - int fd = open(name8.string(), flags, realMode); + int fd = open(name8.c_str(), flags, realMode); if (fd < 0) { jniThrowException(env, "java/io/FileNotFoundException", strerror(errno)); return NULL;