Skip to content

Commit b24e1f3

Browse files
committed
PDFBOX-5896: avoid endless recursion, as suggested by james
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1921739 13f79535-47bb-0310-9956-ffa450edef68
1 parent 55cf202 commit b24e1f3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldFactory.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

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

20+
import java.util.HashSet;
21+
import java.util.Set;
2022
import org.apache.pdfbox.cos.COSArray;
2123
import org.apache.pdfbox.cos.COSBase;
2224
import org.apache.pdfbox.cos.COSDictionary;
@@ -67,7 +69,7 @@ public static PDField createField(PDAcroForm form, COSDictionary field, PDNonTer
6769
}
6870
}
6971

70-
String fieldType = findFieldType(field);
72+
String fieldType = findFieldType(field, new HashSet<>());
7173

7274
if (FIELD_TYPE_CHOICE.equals(fieldType))
7375
{
@@ -127,14 +129,20 @@ else if ((flags & PDButton.FLAG_PUSHBUTTON) != 0)
127129
}
128130
}
129131

130-
private static String findFieldType(COSDictionary dic)
132+
private static String findFieldType(COSDictionary dic, Set<COSDictionary> seen)
131133
{
134+
if (!seen.add(dic))
135+
{
136+
// PDFBOX-5896: avoid endless recursion
137+
return null;
138+
}
132139
String retval = dic.getNameAsString(COSName.FT);
133140
if (retval == null)
134141
{
135142
COSDictionary base = dic.getCOSDictionary(COSName.PARENT, COSName.P);
136-
return base != null ? findFieldType(base):null;
143+
return base != null ? findFieldType(base, seen) : null;
137144
}
145+
seen.remove(dic);
138146
return retval;
139147
}
140148
}

0 commit comments

Comments
 (0)