[ 
https://issues.apache.org/jira/browse/PDFBOX-4859?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17126081#comment-17126081
 ] 

Tilman Hausherr edited comment on PDFBOX-4859 at 6/4/20, 5:20 PM:
------------------------------------------------------------------

I tried it with jdk8, 11 and 14 without trouble and used this code:
{code:java}
public class PDFBox4859_InflateTest
{
    public static void main(String[] args) throws DataFormatException, 
IOException
    {
        String dir = "XXXXXXXXXX";
       
        File inFile = new File(dir, "FontFile2.flatencoded");
        File ttfFile = new File(dir, "flatendecoded.ttf");
        try (InputStream in = new FileInputStream(inFile);
                OutputStream out = new FileOutputStream(ttfFile))
        {
            byte[] buf = new byte[2048];
            // skip zlib header
            in.read();
            in.read();
            int read = in.read(buf);
            Inflater inflater = new Inflater(true);
            inflater.setInput(buf, 0, read);
            byte[] res = new byte[1024];
            boolean dataWritten = false;
            try
            {
                while (true)
                {
                    int resRead = 0;
                    try
                    {
                        resRead = inflater.inflate(res);
                    }
                    catch (DataFormatException exception)
                    {
                        if (dataWritten)
                        {
                            // some data could be read -> don't throw an 
exception
                            System.err.println("FlateFilter: premature end of 
stream due to a DataFormatException");
                            break;
                        }
                        else
                        {
                            // nothing could be read -> re-throw exception
                            throw exception;
                        }
                    }
                    if (resRead != 0)
                    {
                        out.write(res, 0, resRead);
                        dataWritten = true;
                        continue;
                    }
                    if (inflater.finished() || inflater.needsDictionary() || 
in.available() == 0)
                    {
                        break;
                    }
                    read = in.read(buf);
                    inflater.setInput(buf, 0, read);
                }
            }
            finally
            {
                inflater.end();
            }
        }
        TrueTypeFont ttf = new TTFParser(true).parse(ttfFile);
        ttf.close();
    }
}
 {code}


was (Author: tilman):
I tried it with jdk8 and 14 without trouble and used this code:
{code:java}
public class PDFBox4859_InflateTest
{
    public static void main(String[] args) throws DataFormatException, 
IOException
    {
        String dir = "XXXXXXXXXX";
       
        File inFile = new File(dir, "FontFile2.flatencoded");
        File ttfFile = new File(dir, "flatendecoded.ttf");
        try (InputStream in = new FileInputStream(inFile);
                OutputStream out = new FileOutputStream(ttfFile))
        {
            byte[] buf = new byte[2048];
            // skip zlib header
            in.read();
            in.read();
            int read = in.read(buf);
            Inflater inflater = new Inflater(true);
            inflater.setInput(buf, 0, read);
            byte[] res = new byte[1024];
            boolean dataWritten = false;
            try
            {
                while (true)
                {
                    int resRead = 0;
                    try
                    {
                        resRead = inflater.inflate(res);
                    }
                    catch (DataFormatException exception)
                    {
                        if (dataWritten)
                        {
                            // some data could be read -> don't throw an 
exception
                            System.err.println("FlateFilter: premature end of 
stream due to a DataFormatException");
                            break;
                        }
                        else
                        {
                            // nothing could be read -> re-throw exception
                            throw exception;
                        }
                    }
                    if (resRead != 0)
                    {
                        out.write(res, 0, resRead);
                        dataWritten = true;
                        continue;
                    }
                    if (inflater.finished() || inflater.needsDictionary() || 
in.available() == 0)
                    {
                        break;
                    }
                    read = in.read(buf);
                    inflater.setInput(buf, 0, read);
                }
            }
            finally
            {
                inflater.end();
            }
        }
        TrueTypeFont ttf = new TTFParser(true).parse(ttfFile);
        ttf.close();
    }
}
 {code}

> Reading embedded font throws java.io.EOFException: null - Regression from 
> 2.0.9
> -------------------------------------------------------------------------------
>
>                 Key: PDFBOX-4859
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4859
>             Project: PDFBox
>          Issue Type: Bug
>          Components: FontBox
>    Affects Versions: 2.0.19
>         Environment: Windows 10 - Java AdoptOpenJDK 11.0.7
>            Reporter: Wim Maerevoet
>            Priority: Major
>         Attachments: FontFile2.flatencoded
>
>
> With an invoice from Google which can be visualised perfectly with version 
> 2.0.9, I get the following stacktrace with version 2.0.19
>  
> org.apache.pdfbox.pdmodel.font.PDTrueTypeFont - Could not read embedded TTF 
> for font PXAAAA+Roboto
> java.io.EOFException: null
>  at 
> org.apache.fontbox.ttf.MemoryTTFDataStream.readUnsignedShort(MemoryTTFDataStream.java:120)
>  at org.apache.fontbox.ttf.NameRecord.initData(NameRecord.java:172)
>  at org.apache.fontbox.ttf.NamingTable.read(NamingTable.java:70)
>  at org.apache.fontbox.ttf.TrueTypeFont.readTable(TrueTypeFont.java:353)
>  at org.apache.fontbox.ttf.TTFParser.parseTables(TTFParser.java:173)
>  at org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:150)
>  at org.apache.fontbox.ttf.TTFParser.parse(TTFParser.java:106)
>  at 
> org.apache.pdfbox.pdmodel.font.PDTrueTypeFont.<init>(PDTrueTypeFont.java:198)
>  at 
> org.apache.pdfbox.pdmodel.font.PDFontFactory.createFont(PDFontFactory.java:89)
>  at org.apache.pdfbox.pdmodel.PDResources.getFont(PDResources.java:146)
>  at 
> org.apache.pdfbox.contentstream.operator.text.SetFontAndSize.process(SetFontAndSize.java:66)
>  at 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:875)
>  at 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:509)
>  at 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:483)
>  at 
> org.apache.pdfbox.contentstream.PDFStreamEngine.showForm(PDFStreamEngine.java:187)
>  at org.apache.pdfbox.rendering.PageDrawer.showForm(PageDrawer.java:1410)
>  at 
> org.apache.pdfbox.contentstream.operator.graphics.DrawObject.process(DrawObject.java:86)
>  at 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:875)
>  at 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:509)
>  at 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:483)
>  at 
> org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:156)
>  at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:270)
>  at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:321)
>  at org.apache.pdfbox.rendering.PDFRenderer.renderImage(PDFRenderer.java:243)
>  at 
> org.apache.pdfbox.rendering.PDFRenderer.renderImageWithDPI(PDFRenderer.java:229)



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to