You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2014/11/19 11:19:24 UTC

svn commit: r1640514 - in /pdfbox/branches/1.8: ./ preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java

Author: lehmi
Date: Wed Nov 19 10:19:24 2014
New Revision: 1640514

URL: http://svn.apache.org/r1640514
Log:
PDFBOX-2502: compare IDs only if both are available

Modified:
    pdfbox/branches/1.8/   (props changed)
    pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java

Propchange: pdfbox/branches/1.8/
------------------------------------------------------------------------------
  Merged /pdfbox/trunk:r1640513

Modified: pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java?rev=1640514&r1=1640513&r2=1640514&view=diff
==============================================================================
--- pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java (original)
+++ pdfbox/branches/1.8/preflight/src/main/java/org/apache/pdfbox/preflight/process/TrailerValidationProcess.java Wed Nov 19 10:19:24 2014
@@ -80,7 +80,6 @@ public class TrailerValidationProcess ex
             {
                 checkTrailersForLinearizedPDF15(ctx);
             }
-
         }
         else
         {
@@ -90,7 +89,7 @@ public class TrailerValidationProcess ex
     }
 
     /**
-     * Extracts and compares first and last trailers for PDF version between 1.1 and 1.4
+     * Extracts and compares first and last trailers for PDF version between 1.1 and 1.4.
      * 
      * @param ctx
      * @param result
@@ -134,11 +133,9 @@ public class TrailerValidationProcess ex
             {
                 // no XRef CosObject, may by this pdf file used the PDF 1.4 syntaxe
                 checkTrailersForLinearizedPDF14(ctx);
-
             }
             else
             {
-
                 long min = Long.MAX_VALUE;
                 long max = Long.MIN_VALUE;
                 COSDictionary firstTrailer = null;
@@ -189,43 +186,51 @@ public class TrailerValidationProcess ex
     {
         COSBase idFirst = first.getItem(COSName.getPDFName(TRAILER_DICTIONARY_KEY_ID));
         COSBase idLast = last.getItem(COSName.getPDFName(TRAILER_DICTIONARY_KEY_ID));
-
-        if (idFirst == null || idLast == null)
-        {
-            return false;
-        }
-
-        // ---- cast two COSBase to COSArray.
-        COSArray af = COSUtils.getAsArray(idFirst, cosDocument);
-        COSArray al = COSUtils.getAsArray(idLast, cosDocument);
-
-        // ---- if one COSArray is null, the PDF/A isn't valid
-        if ((af == null) || (al == null))
-        {
-            return false;
-        }
-
-        // ---- compare both arrays
-        boolean isEqual = true;
-        for (Object of : af.toList())
-        {
-            boolean oneIsEquals = false;
-            for (Object ol : al.toList())
+        // According to the revised PDF/A specification the IDs have to be identical
+        // if both are present, otherwise everything is fine
+        if (idFirst != null && idLast != null)
+        {
+    
+            // ---- cast two COSBase to COSArray.
+            COSArray af = COSUtils.getAsArray(idFirst, cosDocument);
+            COSArray al = COSUtils.getAsArray(idLast, cosDocument);
+    
+            // ---- if one COSArray is null, the PDF/A isn't valid
+            if ((af == null) || (al == null))
+            {
+                return false;
+            }
+    
+            // ---- compare both arrays
+            boolean isEqual = true;
+            for (Object of : af.toList())
             {
-                // ---- according to PDF Reference 1-4, ID is an array containing two
-                // strings
-                if (!oneIsEquals)
-                    oneIsEquals = ((COSString) ol).getString().equals(((COSString) of).getString());
-                else
+                boolean oneIsEquals = false;
+                for (Object ol : al.toList())
+                {
+                    // ---- according to PDF Reference 1-4, ID is an array containing two
+                    // strings
+                    if (!oneIsEquals)
+                    {
+                        oneIsEquals = ((COSString) ol).getString().equals(((COSString) of).getString());
+                    }
+                    else
+                    {
+                        break;
+                    }
+                }
+                isEqual = isEqual && oneIsEquals;
+                if (!isEqual)
+                {
                     break;
+                }
             }
-            isEqual = isEqual && oneIsEquals;
-            if (!isEqual)
-            {
-                break;
-            }
+            return isEqual;
+        }
+        else
+        {
+            return true;
         }
-        return isEqual;
     }
 
     /**