Skip to content

Commit

Permalink
PDFBOX-5896: avoid endless recursion, as suggested by james
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1921739 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Nov 1, 2024
1 parent 55cf202 commit b24e1f3
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.pdfbox.pdmodel.interactive.form;

import java.util.HashSet;
import java.util.Set;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSBase;
import org.apache.pdfbox.cos.COSDictionary;
Expand Down Expand Up @@ -67,7 +69,7 @@ public static PDField createField(PDAcroForm form, COSDictionary field, PDNonTer
}
}

String fieldType = findFieldType(field);
String fieldType = findFieldType(field, new HashSet<>());

if (FIELD_TYPE_CHOICE.equals(fieldType))
{
Expand Down Expand Up @@ -127,14 +129,20 @@ else if ((flags & PDButton.FLAG_PUSHBUTTON) != 0)
}
}

private static String findFieldType(COSDictionary dic)
private static String findFieldType(COSDictionary dic, Set<COSDictionary> seen)
{
if (!seen.add(dic))
{
// PDFBOX-5896: avoid endless recursion
return null;
}
String retval = dic.getNameAsString(COSName.FT);
if (retval == null)
{
COSDictionary base = dic.getCOSDictionary(COSName.PARENT, COSName.P);
return base != null ? findFieldType(base):null;
return base != null ? findFieldType(base, seen) : null;
}
seen.remove(dic);
return retval;
}
}

0 comments on commit b24e1f3

Please sign in to comment.