[gs-commits] ghostpdl branch, master, updated. jbig2dec-0.14-1804-g27409d9

[email protected] (Ken Sharp) Tue, 5 Nov 2019 08:50:56 +0000 (UTC)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
The ghostpdl branch, master has been updated
       via  27409d99b069e434c6863f43456cf8985bbdf7f8 (commit)
       via  407c98a38c3a6ac1681144ed45cc2f4fc374c91f (commit)
      from  af004276fd8f6c305727183c159b83021020f7d6 (commit)

----------------------------------------------------------------------
commit 27409d99b069e434c6863f43456cf8985bbdf7f8
Author: Ken Sharp <[email protected]>
Date:   Tue Nov 5 08:50:45 2019 +0000

    Fix the quad glyph table
    
    This might fix Coverity ID 350194. Even if it doesn't it is incorrect
    so fix the initialisation of the table.

diff --git a/devices/vector/gdevagl.c b/devices/vector/gdevagl.c
index b2813e0..f9428a6 100644
--- a/devices/vector/gdevagl.c
+++ b/devices/vector/gdevagl.c
@@ -4308,5 +4308,5 @@ treble_glyph_list_t TrebleGlyphList[] = {
 
 quad_glyph_list_t QuadGlyphList[] = {
     {"rehyehaleflamarabic", {0x0631, 0xFEF3, 0xFE8E, 0x0644}},
-    {0x00, {0,0,0}}
+    {0x00, {0,0,0,0}}
 };

----------------------------------------------------------------------
commit 407c98a38c3a6ac1681144ed45cc2f4fc374c91f
Author: Ken Sharp <[email protected]>
Date:   Tue Nov 5 08:48:10 2019 +0000

    txtwrite - guard against using GS_NO_GLYPH to retrieve Unicode values
    
    Bug 701822 "Segmentation fault at psi/iname.c:296 in names_index_ref"
    
    Avoid using a glyph with the value GS_NO_GLYPH to retrieve a glyph
    name or Unicode code point from the glyph ID, as this is not a valid
    ID.

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


Summary of changes:
 devices/vector/gdevagl.c  |   2 +-
 devices/vector/gdevtxtw.c | 160 +++++++++++++++++++++++-----------------------
 psi/zbfont.c              |   2 +-
 3 files changed, 83 insertions(+), 81 deletions(-)