Skip to content

Commit

Permalink
PDFBOX-5707: avoid NPE when collecting all indirect objects keys of a…
Browse files Browse the repository at this point in the history
… COSArray/COSDictionary

git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1913426 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
lehmi committed Oct 29, 2023
1 parent 13dd016 commit 18a1931
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 11 additions & 2 deletions pdfbox/src/main/java/org/apache/pdfbox/cos/COSArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ public void add( COSBase object )
*/
public void add( COSObjectable object )
{
objects.add( object.getCOSObject() );
getUpdateState().update(object.getCOSObject());
COSBase base = null;
if (object != null)
{
base = object.getCOSObject();
}
objects.add(base);
getUpdateState().update(base);
}

/**
Expand Down Expand Up @@ -764,6 +769,10 @@ public void getIndirectObjectKeys(List<COSObjectKey> indirectObjects)

for (COSBase cosBase : objects)
{
if (cosBase == null)
{
continue;
}
COSObjectKey cosBaseKey = cosBase.getKey();
if (cosBaseKey != null && indirectObjects.contains(cosBaseKey))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ public void getIndirectObjectKeys(List<COSObjectKey> indirectObjects)
for (Entry<COSName, COSBase> entry : items.entrySet())
{
COSBase cosBase = entry.getValue();
COSObjectKey cosBaseKey = cosBase.getKey();
COSObjectKey cosBaseKey = cosBase != null ? cosBase.getKey() : null;
// avoid endless recursions
if (COSName.PARENT.equals(entry.getKey())
|| (cosBaseKey != null && indirectObjects.contains(cosBaseKey)))
Expand Down

0 comments on commit 18a1931

Please sign in to comment.