Blame SOURCES/ghostscript-cve-2020-16307.patch

8d372f
diff --git a/devices/vector/gdevtxtw.c b/devices/vector/gdevtxtw.c
8d372f
index b958027..7f02608 100644
8d372f
--- a/devices/vector/gdevtxtw.c
8d372f
+++ b/devices/vector/gdevtxtw.c
8d372f
@@ -1693,97 +1693,100 @@ static int get_unicode(textw_text_enum_t *penum, gs_font *font, gs_glyph glyph,
8d372f
 
8d372f
     length = font->procs.decode_glyph((gs_font *)font, glyph, ch, NULL, 0);
8d372f
     if (length == 0) {
8d372f
-        code = font->procs.glyph_name(font, glyph, &gnstr);
8d372f
-        if (code >= 0 && gnstr.size == 7) {
8d372f
-            if (!memcmp(gnstr.data, "uni", 3)) {
8d372f
-                static const char *hexdigits = "0123456789ABCDEF";
8d372f
-                char *d0 = strchr(hexdigits, gnstr.data[3]);
8d372f
-                char *d1 = strchr(hexdigits, gnstr.data[4]);
8d372f
-                char *d2 = strchr(hexdigits, gnstr.data[5]);
8d372f
-                char *d3 = strchr(hexdigits, gnstr.data[6]);
8d372f
-
8d372f
-                if (d0 != NULL && d1 != NULL && d2 != NULL && d3 != NULL) {
8d372f
-                    *Buffer++ = ((d0 - hexdigits) << 12) + ((d1 - hexdigits) << 8) + ((d2 - hexdigits) << 4) + (d3 - hexdigits);
8d372f
-                    return 1;
8d372f
-                }
8d372f
-            }
8d372f
-        }
8d372f
-        if (length == 0) {
8d372f
-            single_glyph_list_t *sentry = (single_glyph_list_t *)&SingleGlyphList;
8d372f
-            double_glyph_list_t *dentry = (double_glyph_list_t *)&DoubleGlyphList;
8d372f
-            treble_glyph_list_t *tentry = (treble_glyph_list_t *)&TrebleGlyphList;
8d372f
-            quad_glyph_list_t *qentry = (quad_glyph_list_t *)&QuadGlyphList;
8d372f
-
8d372f
-            /* Search glyph to single Unicode value table */
8d372f
-            while (sentry->Glyph != 0) {
8d372f
-                if (sentry->Glyph[0] < gnstr.data[0]) {
8d372f
-                    sentry++;
8d372f
-                    continue;
8d372f
-                }
8d372f
-                if (sentry->Glyph[0] > gnstr.data[0]){
8d372f
-                    break;
8d372f
-                }
8d372f
-                if (strlen(sentry->Glyph) == gnstr.size) {
8d372f
-                    if(memcmp(gnstr.data, sentry->Glyph, gnstr.size) == 0) {
8d372f
-                        *Buffer = sentry->Unicode;
8d372f
+        if (glyph != GS_NO_GLYPH) {
8d372f
+            code = font->procs.glyph_name(font, glyph, &gnstr);
8d372f
+            if (code >= 0 && gnstr.size == 7) {
8d372f
+                if (!memcmp(gnstr.data, "uni", 3)) {
8d372f
+                    static const char *hexdigits = "0123456789ABCDEF";
8d372f
+                    char *d0 = strchr(hexdigits, gnstr.data[3]);
8d372f
+                    char *d1 = strchr(hexdigits, gnstr.data[4]);
8d372f
+                    char *d2 = strchr(hexdigits, gnstr.data[5]);
8d372f
+                    char *d3 = strchr(hexdigits, gnstr.data[6]);
8d372f
+
8d372f
+                    if (d0 != NULL && d1 != NULL && d2 != NULL && d3 != NULL) {
8d372f
+                        *Buffer++ = ((d0 - hexdigits) << 12) + ((d1 - hexdigits) << 8) + ((d2 - hexdigits) << 4) + (d3 - hexdigits);
8d372f
                         return 1;
8d372f
                     }
8d372f
                 }
8d372f
-                sentry++;
8d372f
             }
8d372f
 
8d372f
-            /* Search glyph to double Unicode value table */
8d372f
-            while (dentry->Glyph != 0) {
8d372f
-                if (dentry->Glyph[0] < gnstr.data[0]) {
8d372f
-                    dentry++;
8d372f
-                    continue;
8d372f
-                }
8d372f
-                if (dentry->Glyph[0] > gnstr.data[0]){
8d372f
-                    break;
8d372f
-                }
8d372f
-                if (strlen(dentry->Glyph) == gnstr.size) {
8d372f
-                    if(memcmp(gnstr.data, dentry->Glyph, gnstr.size) == 0) {
8d372f
-                        memcpy(Buffer, dentry->Unicode, 2);
8d372f
-                        return 2;
8d372f
+            if (length == 0) {
8d372f
+                single_glyph_list_t *sentry = (single_glyph_list_t *)&SingleGlyphList;
8d372f
+                double_glyph_list_t *dentry = (double_glyph_list_t *)&DoubleGlyphList;
8d372f
+                treble_glyph_list_t *tentry = (treble_glyph_list_t *)&TrebleGlyphList;
8d372f
+                quad_glyph_list_t *qentry = (quad_glyph_list_t *)&QuadGlyphList;
8d372f
+
8d372f
+                /* Search glyph to single Unicode value table */
8d372f
+                while (sentry->Glyph != 0) {
8d372f
+                    if (sentry->Glyph[0] < gnstr.data[0]) {
8d372f
+                        sentry++;
8d372f
+                        continue;
8d372f
+                    }
8d372f
+                    if (sentry->Glyph[0] > gnstr.data[0]){
8d372f
+                        break;
8d372f
+                    }
8d372f
+                    if (strlen(sentry->Glyph) == gnstr.size) {
8d372f
+                        if(memcmp(gnstr.data, sentry->Glyph, gnstr.size) == 0) {
8d372f
+                            *Buffer = sentry->Unicode;
8d372f
+                            return 1;
8d372f
+                        }
8d372f
                     }
8d372f
+                    sentry++;
8d372f
                 }
8d372f
-                dentry++;
8d372f
-            }
8d372f
 
8d372f
-            /* Search glyph to triple Unicode value table */
8d372f
-            while (tentry->Glyph != 0) {
8d372f
-                if (tentry->Glyph[0] < gnstr.data[0]) {
8d372f
-                    tentry++;
8d372f
-                    continue;
8d372f
-                }
8d372f
-                if (tentry->Glyph[0] > gnstr.data[0]){
8d372f
-                    break;
8d372f
-                }
8d372f
-                if (strlen(tentry->Glyph) == gnstr.size) {
8d372f
-                    if(memcmp(gnstr.data, tentry->Glyph, gnstr.size) == 0) {
8d372f
-                        memcpy(Buffer, tentry->Unicode, 3);
8d372f
-                        return 3;
8d372f
+                /* Search glyph to double Unicode value table */
8d372f
+                while (dentry->Glyph != 0) {
8d372f
+                    if (dentry->Glyph[0] < gnstr.data[0]) {
8d372f
+                        dentry++;
8d372f
+                        continue;
8d372f
                     }
8d372f
+                    if (dentry->Glyph[0] > gnstr.data[0]){
8d372f
+                        break;
8d372f
+                    }
8d372f
+                    if (strlen(dentry->Glyph) == gnstr.size) {
8d372f
+                        if(memcmp(gnstr.data, dentry->Glyph, gnstr.size) == 0) {
8d372f
+                            memcpy(Buffer, dentry->Unicode, 2);
8d372f
+                            return 2;
8d372f
+                        }
8d372f
+                    }
8d372f
+                    dentry++;
8d372f
                 }
8d372f
-                tentry++;
8d372f
-            }
8d372f
 
8d372f
-            /* Search glyph to quadruple Unicode value table */
8d372f
-            while (qentry->Glyph != 0) {
8d372f
-                if (qentry->Glyph[0] < gnstr.data[0]) {
8d372f
-                    qentry++;
8d372f
-                    continue;
8d372f
-                }
8d372f
-                if (qentry->Glyph[0] > gnstr.data[0]){
8d372f
-                    break;
8d372f
+                /* Search glyph to triple Unicode value table */
8d372f
+                while (tentry->Glyph != 0) {
8d372f
+                    if (tentry->Glyph[0] < gnstr.data[0]) {
8d372f
+                        tentry++;
8d372f
+                        continue;
8d372f
+                    }
8d372f
+                    if (tentry->Glyph[0] > gnstr.data[0]){
8d372f
+                        break;
8d372f
+                    }
8d372f
+                    if (strlen(tentry->Glyph) == gnstr.size) {
8d372f
+                        if(memcmp(gnstr.data, tentry->Glyph, gnstr.size) == 0) {
8d372f
+                            memcpy(Buffer, tentry->Unicode, 3);
8d372f
+                            return 3;
8d372f
+                        }
8d372f
+                    }
8d372f
+                    tentry++;
8d372f
                 }
8d372f
-                if (strlen(qentry->Glyph) == gnstr.size) {
8d372f
-                    if(memcmp(gnstr.data, qentry->Glyph, gnstr.size) == 0) {
8d372f
-                        memcpy(Buffer, qentry->Unicode, 4);
8d372f
-                        return 4;
8d372f
+
8d372f
+                /* Search glyph to quadruple Unicode value table */
8d372f
+                while (qentry->Glyph != 0) {
8d372f
+                    if (qentry->Glyph[0] < gnstr.data[0]) {
8d372f
+                        qentry++;
8d372f
+                        continue;
8d372f
+                    }
8d372f
+                    if (qentry->Glyph[0] > gnstr.data[0]){
8d372f
+                        break;
8d372f
                     }
8d372f
+                    if (strlen(qentry->Glyph) == gnstr.size) {
8d372f
+                        if(memcmp(gnstr.data, qentry->Glyph, gnstr.size) == 0) {
8d372f
+                            memcpy(Buffer, qentry->Unicode, 4);
8d372f
+                            return 4;
8d372f
+                        }
8d372f
+                    }
8d372f
+                    qentry++;
8d372f
                 }
8d372f
-                qentry++;
8d372f
             }
8d372f
         }
8d372f
         *Buffer = fallback;
8d372f
@@ -1890,8 +1893,8 @@ txtwrite_process_cmap_text(gs_text_enum_t *pte)
8d372f
                 pte->returned.total_width.x += dpt.x;
8d372f
                 pte->returned.total_width.y += dpt.y;
8d372f
 
8d372f
-                penum->TextBufferIndex += get_unicode(penum, (gs_font *)pte->orig_font, glyph, chr, &penum->TextBuffer[penum->TextBufferIndex]);
8d372f
                 penum->Widths[penum->TextBufferIndex] += dpt.x;
8d372f
+                penum->TextBufferIndex += get_unicode(penum, (gs_font *)pte->orig_font, glyph, chr, &penum->TextBuffer[penum->TextBufferIndex]);
8d372f
                 break;
8d372f
             case 2:		/* end of string */
8d372f
                 return 0;
8d372f
diff --git a/psi/zbfont.c b/psi/zbfont.c
8d372f
index 262fea9..abc03aa 100644
8d372f
--- a/psi/zbfont.c
8d372f
+++ b/psi/zbfont.c
8d372f
@@ -272,7 +272,7 @@ gs_font_map_glyph_to_unicode(gs_font *font, gs_glyph glyph, int ch, ushort *u, u
8d372f
          * can't be a default value for FontInfo.GlyphNames2Unicode .
8d372f
          */
8d372f
     }
8d372f
-    if (glyph <= GS_MIN_CID_GLYPH) {
8d372f
+    if (glyph <= GS_MIN_CID_GLYPH && glyph != GS_NO_GLYPH) {
8d372f
         UnicodeDecoding = zfont_get_to_unicode_map(font->dir);
8d372f
         if (UnicodeDecoding != NULL && r_type(UnicodeDecoding) == t_dictionary)
8d372f
             return gs_font_map_glyph_by_dict(font->memory, UnicodeDecoding, glyph, u, length);