You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2020/07/01 19:25:00 UTC

[jira] [Commented] (PDFBOX-4906) PDOptionalContentProperties hasGroup can null pointer if OCGs data is missing

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

ASF subversion and git services commented on PDFBOX-4906:
---------------------------------------------------------

Commit 1879410 from Tilman Hausherr in branch 'pdfbox/branches/2.0'
[ https://svn.apache.org/r1879410 ]

PDFBOX-4906: avoid NPE

> PDOptionalContentProperties hasGroup can null pointer if OCGs data is missing
> -----------------------------------------------------------------------------
>
>                 Key: PDFBOX-4906
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4906
>             Project: PDFBox
>          Issue Type: Bug
>    Affects Versions: 2.0.13, 2.0.20
>            Reporter: Ryan Rupp
>            Priority: Trivial
>             Fix For: 2.0.21, 3.0.0 PDFBox
>
>
> I've noticed the following null pointer exception can happen on scanned documents when we're checking if it has a layer of a given name:
> {code:java}
> java.lang.NullPointerExceptionjava.lang.NullPointerException at org.apache.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentProperties.getGroupNames(PDOptionalContentProperties.java:227) at org.apache.pdfbox.pdmodel.graphics.optionalcontent.PDOptionalContentProperties.hasGroup(PDOptionalContentProperties.java:245)
> {code}
> Looking into this, it happens because for these particular documents the following line returns null - [https://github.com/apache/pdfbox/blob/da378798e5f2c8a1394725518db478f7ffaf5177/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentProperties.java#L227]
> and subsequently gets dereferenced
> It may be that these files are just generated in an invalid way (unfortunately I cannot provide them as it contains customer information). Anyway, looking at the code other methods getGroup(name) call a private method getOCGs that safeguards against the null case by defaulting it then, see here - [https://github.com/apache/pdfbox/blob/da378798e5f2c8a1394725518db478f7ffaf5177/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/graphics/optionalcontent/PDOptionalContentProperties.java#L118]
> So maybe getGroupNames() (which hasGroup uses) can just use that as a safeguard? Anyway, the workaround was to replace our hasGroup(name) check with getGroup(name) != null



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

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