diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2017-05-12 22:48:36 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2017-05-12 22:48:36 +0300 |
commit | 37d630875d33bf3c291026c40bb08d1b6c9edcc8 (patch) | |
tree | 68fb026f54a962cf1d631f010e98681add6ed014 /debian/patches/jdk-freetypeScaler-crash.diff | |
download | openjdk-8-debian.tar.gz |
Imported debian/openjdk-8_8u131-b11-1debian/8u131-b11-1debian
Diffstat (limited to 'debian/patches/jdk-freetypeScaler-crash.diff')
-rw-r--r-- | debian/patches/jdk-freetypeScaler-crash.diff | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/debian/patches/jdk-freetypeScaler-crash.diff b/debian/patches/jdk-freetypeScaler-crash.diff new file mode 100644 index 0000000..4d68018 --- /dev/null +++ b/debian/patches/jdk-freetypeScaler-crash.diff @@ -0,0 +1,129 @@ +Description: + + Fixing the bad JNI code in the font manager code. Two issues: + + o The JNIEnv is unique to the thread. It cannot be saved by one thread and + reused by another. Use GetEnv instead. + + o The 'font2D' jobject needs to be converted into a global reference because + its lifetime exceeds the lifetime of a native method call. + +Evaluation: + +Appropriately register/free everything with the garbage collector. + +Fix: + +# HG changeset patch +# User martin +# Date 1224202830 25200 +# Node ID 3c9d6001d8a90698a3540a2a483717f26a98db78 +# Parent 68730f05449cd4f39ce1cb82adc6c4e57f87554f +Crash in freetypeScaler.c due to insufficient GC protection +Summary: NewGlobalRef/DeleteGlobalRef as needed. +Reviewed-by: +Contributed-by: yamauchi@google.com + +--- a/jdk/make/mapfiles/libfontmanager/mapfile-vers.openjdk ++++ b/jdk/make/mapfiles/libfontmanager/mapfile-vers.openjdk +@@ -29,6 +29,7 @@ + + SUNWprivate_1.1 { + global: ++ JNI_OnLoad; + getSunFontIDs; + newLayoutTableCache; + freeLayoutTableCache; +--- a/jdk/src/share/native/sun/font/freetypeScaler.c ++++ b/jdk/src/share/native/sun/font/freetypeScaler.c +@@ -48,16 +48,6 @@ + #define ROUND(x) ((int) (x+0.5)) + + typedef struct { +- /* Important note: +- JNI forbids sharing same env between different threads. +- We are safe, because pointer is overwritten every time we get into +- JNI call (see setupFTContext). +- +- Pointer is used by font data reading callbacks +- such as ReadTTFontFileFunc. +- +- NB: We may consider switching to JNI_GetEnv. */ +- JNIEnv* env; + FT_Library library; + FT_Face face; + jobject font2D; +@@ -90,6 +80,13 @@ int z_verbose; + void z_error(char *s) {} + #endif + ++static JavaVM* jvm = NULL; ++ ++JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { ++ jvm = vm; ++ return JNI_VERSION_1_2; ++} ++ + /**************** Error handling utilities *****************/ + + static jmethodID invalidateScalerMID; +@@ -120,6 +117,10 @@ static void freeNativeResources(JNIEnv * + FT_Done_Face(scalerInfo->face); + FT_Done_FreeType(scalerInfo->library); + ++ if (scalerInfo->font2D != NULL) { ++ (*env)->DeleteGlobalRef(env, scalerInfo->font2D); ++ } ++ + if (scalerInfo->directBuffer != NULL) { + (*env)->DeleteGlobalRef(env, scalerInfo->directBuffer); + } +@@ -152,8 +153,8 @@ static unsigned long ReadTTFontFileFunc( + unsigned char* destBuffer, + unsigned long numBytes) + { ++ JNIEnv* env = (JNIEnv*) JNU_GetEnv(jvm, JNI_VERSION_1_2); + FTScalerInfo *scalerInfo = (FTScalerInfo *) stream->pathname.pointer; +- JNIEnv* env = scalerInfo->env; + jobject bBuffer; + int bread = 0; + +@@ -229,8 +230,7 @@ Java_sun_font_FreetypeFontScaler_initNat + if (scalerInfo == NULL) + return 0; + +- scalerInfo->env = env; +- scalerInfo->font2D = font2D; ++ scalerInfo->font2D = (*env)->NewGlobalRef(env, font2D); + scalerInfo->fontDataOffset = 0; + scalerInfo->fontDataLength = 0; + scalerInfo->fileSize = filesize; +@@ -247,6 +247,7 @@ Java_sun_font_FreetypeFontScaler_initNat + */ + error = FT_Init_FreeType(&scalerInfo->library); + if (error) { ++ (*env)->DeleteGlobalRef(env, scalerInfo->font2D); + free(scalerInfo); + return 0; + } +@@ -317,6 +318,7 @@ Java_sun_font_FreetypeFontScaler_initNat + } + if (scalerInfo->fontData != NULL) + free(scalerInfo->fontData); ++ (*env)->DeleteGlobalRef(env, scalerInfo->font2D); + free(scalerInfo); + return 0; + } +@@ -377,8 +379,10 @@ static int setupFTContext(JNIEnv *env, + FTScalerContext *context) { + int errCode = 0; + +- scalerInfo->env = env; +- scalerInfo->font2D = font2D; ++ if (scalerInfo->font2D != NULL) { ++ (*env)->DeleteGlobalRef(env, scalerInfo->font2D); ++ } ++ scalerInfo->font2D = (*env)->NewGlobalRef(env, font2D); + + if (context != NULL) { + FT_Set_Transform(scalerInfo->face, &context->transform, NULL); |