f2fcc98
From 329e0a6d187cc5b5698689d76636ed3214d7efa7 Mon Sep 17 00:00:00 2001
f2fcc98
From: Chris Liddell <chris.liddell@artifex.com>
f2fcc98
Date: Thu, 3 Nov 2016 13:09:27 +0000
f2fcc98
Subject: [PATCH] Bug 697286: handle GlyphDirectory as an array
f2fcc98
f2fcc98
For high level devices that need to copy CIDFonts, we need to establish the
f2fcc98
highest CID in a given CIDFont. If the font has a GlyphDirectory dictionary
f2fcc98
the only way to do so is to iterate through the keys to find the highest.
f2fcc98
f2fcc98
The code handling this ignored that the GlyphDirectory could be an array,
f2fcc98
which confused the dictionary content iterator, and caused a segfault.
f2fcc98
f2fcc98
In the case of an array, set the high CID to the highest index available in the
f2fcc98
array.
f2fcc98
---
f2fcc98
 psi/zfcid.c | 18 +++++++++++-------
f2fcc98
 1 file changed, 11 insertions(+), 7 deletions(-)
f2fcc98
f2fcc98
diff --git a/psi/zfcid.c b/psi/zfcid.c
f2fcc98
index ce583af..3098a22 100644
f2fcc98
--- a/psi/zfcid.c
f2fcc98
+++ b/psi/zfcid.c
f2fcc98
@@ -76,15 +76,19 @@ cid_font_data_param(os_ptr op, gs_font_cid_data *pdata, ref *pGlyphDirectory)
f2fcc98
          * the number of CIDs in the font. We need to know the maximum CID
f2fcc98
          * when copying fonts, so calculate and store it now.
f2fcc98
          */
f2fcc98
-        index = dict_first(pgdir);
f2fcc98
-        while (index >= 0) {
f2fcc98
-            index = dict_next(pgdir, index, (ref *)&element);
f2fcc98
-            if (index >= 0) {
f2fcc98
-                if (element[0].value.intval > pdata->MaxCID)
f2fcc98
-                    pdata->MaxCID = element[0].value.intval;
f2fcc98
+        if (r_has_type(pgdir, t_dictionary)) {
f2fcc98
+            index = dict_first(pgdir);
f2fcc98
+            while (index >= 0) {
f2fcc98
+                index = dict_next(pgdir, index, (ref *)&element);
f2fcc98
+                if (index >= 0) {
f2fcc98
+                    if (element[0].value.intval > pdata->MaxCID)
f2fcc98
+                        pdata->MaxCID = element[0].value.intval;
f2fcc98
+                }
f2fcc98
             }
f2fcc98
         }
f2fcc98
-
f2fcc98
+        else {
f2fcc98
+            pdata->MaxCID = r_size(pgdir) - 1;
f2fcc98
+        }
f2fcc98
         return code;
f2fcc98
     } else {
f2fcc98
         return_error(gs_error_typecheck);
f2fcc98
-- 
f2fcc98
2.7.4
f2fcc98