You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2020/12/13 05:35:29 UTC

svn commit: r1884374 - in /pdfbox/branches/2.0/pdfbox/src: main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTree.java test/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeTest.java

Author: tilman
Date: Sun Dec 13 05:35:29 2020
New Revision: 1884374

URL: http://svn.apache.org/viewvc?rev=1884374&view=rev
Log:
PDFBOX-5044: use identity hash set (identity check vs an equality check) as suggested by Maruan Sahyoun; add test

Added:
    pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeTest.java   (with props)
Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTree.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTree.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTree.java?rev=1884374&r1=1884373&r2=1884374&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTree.java (original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTree.java Sun Dec 13 05:35:29 2020
@@ -17,7 +17,9 @@
 package org.apache.pdfbox.pdmodel.interactive.form;
 
 import java.util.ArrayDeque;
+import java.util.Collections;
 import java.util.HashSet;
+import java.util.IdentityHashMap;
 import java.util.Iterator;
 import java.util.Queue;
 
@@ -69,7 +71,8 @@ public class PDFieldTree implements Iter
         
         // PDFBOX-5044: to prevent recursion
         // must be COSDictionary and not PDField, because PDField is newly created each time
-        private final Set<COSDictionary> set = new HashSet<COSDictionary>();
+        private final Set<COSDictionary> set =
+                Collections.newSetFromMap(new IdentityHashMap<COSDictionary, Boolean>());
 
         private FieldIterator(PDAcroForm form)
         {

Added: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeTest.java?rev=1884374&view=auto
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeTest.java (added)
+++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeTest.java Sun Dec 13 05:35:29 2020
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.pdfbox.pdmodel.interactive.form;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDDocumentCatalog;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ * @author Tilman Hausherr
+ */
+public class PDFieldTreeTest
+{
+
+    /**
+     * PDFBOX-5044 stack overflow
+     *
+     * @throws IOException
+     */
+    @Test
+    public void test5044() throws IOException
+    {
+        String sourceUrl = "https://issues.apache.org/jira/secure/attachment/13016994/PDFBOX-4131-0.pdf";
+
+        InputStream is = new URL(sourceUrl).openStream();
+        PDDocument doc = PDDocument.load(is);
+        PDDocumentCatalog catalog = doc.getDocumentCatalog();
+        PDAcroForm acroForm = catalog.getAcroForm();
+        int count = 0;
+        for (PDField field : acroForm.getFieldTree())
+        {
+            ++count;
+        }
+        Assert.assertEquals(4, count);
+        is.close();
+        doc.close();
+    }
+}

Propchange: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native