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

Jacobo Aragunde commented on PDFBOX-6061:
-----------------------------------------

I suspected so, because it was hard to hand-craft a reproducer :D I would have 
preferred to report the problem to the software that generated that PDF in 
first place, unfortunately that's out of my reach.

Thanks for your time!

> NullPointerException in COSDictionary
> -------------------------------------
>
>                 Key: PDFBOX-6061
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-6061
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 2.0.34, 3.0.5 PDFBox
>            Reporter: Jacobo Aragunde
>            Assignee: Tilman Hausherr
>            Priority: Minor
>             Fix For: 2.0.35, 3.0.6 PDFBox, 4.0.0
>
>         Attachments: empty-reproducer.pdf
>
>
> Load the attached PDF file and try to add some text, {*}reusing the PDFont 
> object{*}. This code would reproduce the problem:
>  
>     void convert(OutputStream outputStream) \{
>         PDDocument document = Loader.loadPDF(new 
> File('C:\\path\\to\\empty-reproducer.pdf'))
>         PDPage page = document.getPage(0)
>         new PDPageContentStream(document, page, 
> PDPageContentStream.AppendMode.APPEND, false, false).withCloseable { 
> contentStream ->
>             String text = 'this is some text'
>             PDFont myFont = new 
> PDType1Font(Standard14Fonts.FontName.HELVETICA)
>             contentStream.beginText()
>             contentStream.setFont(myFont, 12)
>             contentStream.newLineAtOffset(25, 0)
>             contentStream.showText(text)
>             contentStream.endText()
>             contentStream.beginText()
>             contentStream.setFont(myFont, 12) // <-- Crash
>             contentStream.newLineAtOffset(25, 25)
>             contentStream.showText(text)
>             contentStream.endText()
>         }
>         document.save(outputStream)
>     }
> The second call to `setFont` will produce this error:
> Exception in thread "main" java.lang.NullPointerException: Cannot invoke 
> "Object.equals(Object)" because the return value of 
> "org.apache.pdfbox.cos.COSObject.getObject()" is null
>       at 
> org.apache.pdfbox.cos.COSDictionary.getKeyForValue(COSDictionary.java:110)
>       at org.apache.pdfbox.pdmodel.PDResources.add(PDResources.java:714)
>       at org.apache.pdfbox.pdmodel.PDResources.add(PDResources.java:598)
>       at 
> org.apache.pdfbox.pdmodel.PDAbstractContentStream.setFont(PDAbstractContentStream.java:218)
>       at 
> org.apache.pdfbox.pdmodel.PDPageContentStream.setFont(PDPageContentStream.java:37)
> The PDF file has been hand-crafted to produce this error, sadly I cannot 
> share the original reproducer. The source of the problem is a null reference 
> in the Font section of the Resources dictionary. The second time we run 
> `setFont`, the font already exists in the dictionary, so it iterates all the 
> elements trying to retrieve the item and crashes on the null reference.
>  



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

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org

Reply via email to