pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1677029 - in /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox: pdfwriter/COSWriter.java pdmodel/encryption/PublicKeySecurityHandler.java pdmodel/encryption/SecurityHandler.java pdmodel/encryption/StandardSecurityHandler.java
Date Thu, 30 Apr 2015 17:08:46 GMT
Author: tilman
Date: Thu Apr 30 17:08:46 2015
New Revision: 1677029

URL: http://svn.apache.org/r1677029
Log:
PDFBOX-2769: avoid NPE if no protection policy when saving

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java?rev=1677029&r1=1677028&r2=1677029&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java Thu
Apr 30 17:08:46 2015
@@ -1422,6 +1422,8 @@ public class COSWriter implements ICOSVi
      * @param doc The document to write.
      *
      * @throws COSVisitorException If an error occurs while generating the data.
+     * @throws IllegalStateException If the document has an encryption dictionary but no
protection
+     * policy.
      */
     public void write(PDDocument doc) throws COSVisitorException
     {
@@ -1451,6 +1453,11 @@ public class COSWriter implements ICOSVi
             {
                 try
                 {
+                    if (!securityHandler.hasProtectionPolicy())
+                    {
+                        throw new IllegalStateException("PDF contains an encryption dictionary,
please remove it with "
+                                + "setAllSecurityToBeRemoved() or set a protection policy
with protect()");
+                    }
                     securityHandler.prepareDocumentForEncryption(document);
                     this.willEncrypt = true;
                 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java?rev=1677029&r1=1677028&r2=1677029&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PublicKeySecurityHandler.java
Thu Apr 30 17:08:46 2015
@@ -431,4 +431,12 @@ public class PublicKeySecurityHandler ex
         return new KeyTransRecipientInfo( recipId, algorithmidentifier, deroctetstring);
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean hasProtectionPolicy()
+    {
+        return policy != null;
+    }
 }

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java?rev=1677029&r1=1677028&r2=1677029&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
Thu Apr 30 17:08:46 2015
@@ -655,4 +655,11 @@ public abstract class SecurityHandler
     {
         aes = aesValue;
     }
-}
+ 
+    /**
+     * Returns whether a protection policy has been set.
+     * 
+     * @return true if a protection policy has been set.
+     */
+    public abstract boolean hasProtectionPolicy();
+}
\ No newline at end of file

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java?rev=1677029&r1=1677028&r2=1677029&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
(original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
Thu Apr 30 17:08:46 2015
@@ -895,4 +895,12 @@ public class StandardSecurityHandler ext
         return true;
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean hasProtectionPolicy()
+    {
+        return policy != null;
+    }
 }



Mime
View raw message