[gs-commits] ghostpdl branch, master, updated. jbig2dec-0.14-1553-gfd915a8

[email protected] (Ken Sharp)
Newsgroups gmane.comp.printing.ghostscript.cvs
Message-ID <[email protected]>
The ghostpdl branch, master has been updated
       via  fd915a81c605a52f58855bd233c19aaa373b2f69 (commit)
      from  5b85ddd19a8420a1bd2d5529325be35d78e94234 (commit)

----------------------------------------------------------------------
commit fd915a81c605a52f58855bd233c19aaa373b2f69
Author: Ken Sharp <[email protected]>
Date:   Mon Aug 5 10:05:58 2019 +0100

    pdfwrite - improve CIDFont generation
    
    Bug 701010 "Low Printer VM and gswinc32.exe crashing on postscript file with Korean text"
    
    The problem in this case is that the PostScript uses a CIDFont with two
    descendant fonts. PDF only permits a single descendant font in a CIDFont
    so pdfwrite can't simply copy the font 'as is'.
    
    Instead we create a type 0 font (CIDFont) for each descendant and switch
    between them as required.
    
    The problem here is that the code for retrieving an existing Type 0
    CIDFont for a given descendant in the PostScript assumed that the name
    of the CIDFont would be of the form /FontName-CMapName, and the font
    we have here does not match that.
    
    In fact, I'm not at all sure that this is *ever* the case, certainly
    none of our test files seem to exercise this (bearing in mind that its
    the Type 0 CIDFont generated by pdfwrite that we are checking against
    and I can see no code that created a name of that form).
    
    So what was happening was that every time the PostScript CIDFont
    switched descendants, we generated a new Yype 0 font, along with all the
    attendant structures, such as a ToUnicode CMap (256kB on its own). In
    fact the first line of text in the file switches descendants 26 times,
    leading to us creating something like 21 MB of extra font information.
    
    We now extend the check so that if the name is not FontName-CMapName we
    check the FontName and the CMap Name (which we do also store) separately
    and if they match we reuse the existing Type 0 font.
    
    The supplied test file now runs to completion, all 217 pages, with a
    peak memory usage of ~22.8MB whereas it previously exhausted memory,
    using ~2GB, at page 111. In addition the resulting PDF file is around
    95% smaller and the performance is noticeably improved on this file.

diff --git a/devices/vector/gdevpdtt.c b/devices/vector/gdevpdtt.c
index 22e91e8..2c571de 100644
--- a/devices/vector/gdevpdtt.c
+++ b/devices/vector/gdevpdtt.c
@@ -1228,11 +1228,28 @@ pdf_find_type0_font_resource(gx_device_pdf *pdev, const pdf_font_resource_t *pds
                 continue;
             if (pdfont->u.type0.font_index != font_index)
                 continue;
-            if (pdfont->BaseFont.size != pdsubf->BaseFont.size + CMapName->size + 1)
-                continue;
-            if (memcmp(pdfont->BaseFont.data + pdsubf->BaseFont.size + 1,
-                        CMapName->data, CMapName->size))
-                continue;
+
+            /* Check to see if the PDF font name is of the form FontName-CMapName
+             * If it is, check the name and cmap against the BaseFont Name and CMap
+             * I'm not certain this is *ever* true.
+             */
+            if (pdfont->BaseFont.size == pdsubf->BaseFont.size + CMapName->size + 1) {
+                if (memcmp(pdfont->BaseFont.data + pdsubf->BaseFont.size + 1,
+                            CMapName->data, CMapName->size))
+                    continue;
+            } else {
+                /* Otherwise, check the PDF font name against the subfont name, and the
+                 * CMap used with the PDF font against the requested CMap. If either differs
+                 * then this PDF font is not usable.
+                 */
+                if (pdfont->BaseFont.size != pdsubf->BaseFont.size)
+                    continue;
+                if (pdfont->u.type0.CMapName.size != CMapName->size)
+                    continue;
+                if (memcmp(pdfont->u.type0.CMapName.data, CMapName->data, CMapName->size))
+                    continue;
+            }
+
             *ppdfont = pdfont;
             return 1;
         }


Summary of changes:
 devices/vector/gdevpdtt.c | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.