8052396: Catch exceptions resulting from missing font cmap
authorprr
Thu, 31 Jul 2014 11:33:36 -0700
changeset 26020 68deef2ad1c9
parent 26019 10a56d28f48d
child 26021 847033cb0339
8052396: Catch exceptions resulting from missing font cmap Reviewed-by: bae, serb
jdk/src/share/classes/sun/font/FileFontStrike.java
jdk/src/share/classes/sun/font/TrueTypeGlyphMapper.java
--- a/jdk/src/share/classes/sun/font/FileFontStrike.java	Thu Jul 31 14:28:10 2014 +0400
+++ b/jdk/src/share/classes/sun/font/FileFontStrike.java	Thu Jul 31 11:33:36 2014 -0700
@@ -454,6 +454,17 @@
 
     /* Only look in the cache */
     long getCachedGlyphPtr(int glyphCode) {
+        try {
+            return getCachedGlyphPtrInternal(glyphCode);
+        } catch (Exception e) {
+          NullFontScaler nullScaler =
+             (NullFontScaler)FontScaler.getNullScaler();
+          long nullSC = NullFontScaler.getNullScalerContext();
+          return nullScaler.getGlyphImage(nullSC, glyphCode);
+        }
+    }
+
+    private long getCachedGlyphPtrInternal(int glyphCode) {
         switch (glyphCacheFormat) {
             case INTARRAY:
                 return intGlyphImages[glyphCode] & INTMASK;
@@ -481,6 +492,27 @@
     }
 
     private synchronized long setCachedGlyphPtr(int glyphCode, long glyphPtr) {
+        try {
+            return setCachedGlyphPtrInternal(glyphCode, glyphPtr);
+        } catch (Exception e) {
+            switch (glyphCacheFormat) {
+                case INTARRAY:
+                case SEGINTARRAY:
+                    StrikeCache.freeIntPointer((int)glyphPtr);
+                    break;
+                case LONGARRAY:
+                case SEGLONGARRAY:
+                    StrikeCache.freeLongPointer(glyphPtr);
+                    break;
+             }
+             NullFontScaler nullScaler =
+                 (NullFontScaler)FontScaler.getNullScaler();
+             long nullSC = NullFontScaler.getNullScalerContext();
+             return nullScaler.getGlyphImage(nullSC, glyphCode);
+        }
+    }
+
+    private long setCachedGlyphPtrInternal(int glyphCode, long glyphPtr) {
         switch (glyphCacheFormat) {
             case INTARRAY:
                 if (intGlyphImages[glyphCode] == 0) {
--- a/jdk/src/share/classes/sun/font/TrueTypeGlyphMapper.java	Thu Jul 31 14:28:10 2014 +0400
+++ b/jdk/src/share/classes/sun/font/TrueTypeGlyphMapper.java	Thu Jul 31 11:33:36 2014 -0700
@@ -59,7 +59,11 @@
         }
         missingGlyph = 0; /* standard for TrueType fonts */
         ByteBuffer buffer = font.getTableBuffer(TrueTypeFont.maxpTag);
-        numGlyphs = buffer.getChar(4); // offset 4 bytes in MAXP table.
+        if (buffer != null && buffer.capacity() >= 6) {
+            numGlyphs = buffer.getChar(4); // offset 4 bytes in MAXP table.
+        } else {
+            handleBadCMAP();
+        }
         if (FontUtilities.isSolaris && isJAlocale && font.supportsJA()) {
             needsJAremapping = true;
             if (FontUtilities.isSolaris8 &&