Stefan Ziegler created PDFBOX-6204:
--------------------------------------

             Summary: DType1FontEmbedder sets /Length to uncompressed PFB size, 
causing broken font streams
                 Key: PDFBOX-6204
                 URL: https://issues.apache.org/jira/browse/PDFBOX-6204
             Project: PDFBox
          Issue Type: Bug
          Components: PDModel
    Affects Versions: 3.0.7 PDFBox
            Reporter: Stefan Ziegler


{{PDType1FontEmbedder}} constructs a {{PDStream}} with {{{}FLATE_DECODE{}}}, 
which correctly sets {{/Length}} to the compressed byte count. It then 
immediately overwrites that value with {{pfbParser.size()}} — the total 
*uncompressed* PFB size:


{code:java}
// PDType1FontEmbedder.java, ~line 80
PDStream fontStream = new PDStream(doc, pfbParser.getInputStream(), 
COSName.FLATE_DECODE);
fontStream.getCOSObject().setInt("Length", pfbParser.size());   // ← wrong: 
uncompressed size
for (int i = 0; i < pfbParser.getLengths().length; i++)
    fontStream.getCOSObject().setInt("Length" + (i + 1), 
pfbParser.getLengths()[i]); // ← correct{code}
Per PDF spec, /Length on a stream must equal the number of bytes of the encoded 
(post-filter) data.

The following line should be completely removed:
{code:java}
fontStream.getCOSObject().setInt("Length", pfbParser.size());{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to