pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1656341 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
Date Sun, 01 Feb 2015 17:54:51 GMT
Author: lehmi
Date: Sun Feb  1 17:54:50 2015
New Revision: 1656341

URL: http://svn.apache.org/r1656341
Log:
PDFBOX-2586: detect and swallow GeneralSecurityException as it used to be done using JVMs
< 1.8 as poroposed by Michele Balistreri

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java?rev=1656341&r1=1656340&r2=1656341&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/SecurityHandler.java
Sun Feb  1 17:54:50 2015
@@ -41,6 +41,8 @@ import javax.crypto.SecretKey;
 import javax.crypto.spec.IvParameterSpec;
 import javax.crypto.spec.SecretKeySpec;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
@@ -60,6 +62,8 @@ import org.apache.pdfbox.pdmodel.PDDocum
  */
 public abstract class SecurityHandler
 {
+    private static final Log LOG = LogFactory.getLog(SecurityHandler.class);
+    
     private static final int DEFAULT_KEY_LENGTH = 40;
 
     // see 7.6.2, page 58, PDF 32000-1:2008
@@ -303,6 +307,16 @@ public abstract class SecurityHandler
         {
             IOUtils.copy(cis, output);
         }
+        catch(IOException exception)
+        {
+            // starting with java 8 the JVM wraps an IOException around a GeneralSecurityException
+            // it should be safe to swallow a GeneralSecurityException
+            if (!(exception.getCause() instanceof GeneralSecurityException)) 
+            {
+                throw exception;
+            }
+            LOG.debug("A GeneralSecurityException occured when decrypting some stream data",
exception);
+        }
         finally
         {
             cis.close();



Mime
View raw message