changeset 9152:1a31f06296eb 8u51-b02

RT-40027: Mac Font Support Reviewed-by: kcr, prr, mschoene, afomin
author vadim
date Mon, 02 Mar 2015 15:35:02 +0300
parents 0c70ed3bce9d
children 6b13c6d79851
files modules/graphics/src/main/java/com/sun/javafx/font/PrismFontFile.java
diffstat 1 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/javafx/font/PrismFontFile.java	Fri Feb 27 13:02:05 2015 -0800
+++ b/modules/graphics/src/main/java/com/sun/javafx/font/PrismFontFile.java	Mon Mar 02 15:35:02 2015 +0300
@@ -512,6 +512,9 @@
 
             setStyle();
 
+            // sanity check the cmap table
+            checkCMAP();
+
             /* Get names last, as the name table is far from the file header.
              * Although its also likely too big to fit in the read cache
              * in which case that would remain valid, but also will help
@@ -824,6 +827,31 @@
         }
     }
 
+    private void checkCMAP() throws Exception {
+        DirectoryEntry cmapDE = getDirectoryEntry(FontConstants.cmapTag);
+        if (cmapDE != null) {
+            if (cmapDE.length < 4) {
+                throw new Exception("Invalid cmap table length");
+            }
+            Buffer cmapTableHeader = filereader.readBlock(cmapDE.offset, 4);
+            short version = cmapTableHeader.getShort();
+            short numberSubTables = cmapTableHeader.getShort();
+            int indexLength = numberSubTables * 8;
+            if (numberSubTables <= 0 || cmapDE.length < indexLength + 4) {
+                throw new Exception("Invalid cmap subtables count");
+            }
+            Buffer cmapTableIndex = filereader.readBlock(cmapDE.offset + 4, indexLength);
+            for (int i = 0; i < numberSubTables; i++) {
+                short platformID = cmapTableIndex.getShort();
+                short encodingID = cmapTableIndex.getShort();
+                int offset = cmapTableIndex.getInt();
+                if (offset < 0 || offset >= cmapDE.length) {
+                    throw new Exception("Invalid cmap subtable offset");
+                }
+            }
+        }
+    }
+    
     /*** BEGIN LOCALE_ID MAPPING ****/
 
     private static Map<String, Short> lcidMap;