Blame SOURCES/ghostscript-handle-glyphdirectory-array.patch

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