pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1847355 - /pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/ValidationResult.java
Date Sat, 24 Nov 2018 10:41:07 GMT
Author: tilman
Date: Sat Nov 24 10:41:07 2018
New Revision: 1847355

URL: http://svn.apache.org/viewvc?rev=1847355&view=rev
Log:
PDFBOX-4384: limit to 10000 errors

Modified:
    pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/ValidationResult.java

Modified: pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/ValidationResult.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/ValidationResult.java?rev=1847355&r1=1847354&r2=1847355&view=diff
==============================================================================
--- pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/ValidationResult.java
(original)
+++ pdfbox/trunk/preflight/src/main/java/org/apache/pdfbox/preflight/ValidationResult.java
Sat Nov 24 10:41:07 2018
@@ -43,6 +43,11 @@ public class ValidationResult
     private List<ValidationError> lErrors = new ArrayList<>();
 
     /**
+     * Max error count, to avoid out of memory.
+     */
+    static private final int MAX_ERRORS = 10000;
+
+    /**
      * Object representation of the XMPMetaData contained by the pdf file This attribute
can be null if the Validation
      * fails.
      */
@@ -70,7 +75,7 @@ public class ValidationResult
         this.isValid = false;
         if (error != null)
         {
-            this.lErrors.add(error);
+            addErrorInternal(error);
         }
     }
 
@@ -137,7 +142,7 @@ public class ValidationResult
         if (error != null)
         {
             this.isValid &= error.isWarning();
-            this.lErrors.add(error);
+            addErrorInternal(error);
         }
     }
 
@@ -165,6 +170,20 @@ public class ValidationResult
         return this.lErrors;
     }
 
+    private void addErrorInternal(ValidationError error)
+    {
+        if (this.lErrors.size() == MAX_ERRORS)
+        {
+            this.lErrors.add(new ValidationError(PreflightConstants.ERROR_UNKOWN_ERROR, "Too
many errors"));
+            return;
+        }
+        if (this.lErrors.size() > MAX_ERRORS)
+        {
+            return;
+        }
+        this.lErrors.add(error);
+    }
+
     /**
      * This Class represents an error of validation. It contains an error code and an error
explanation.
      */



Mime
View raw message