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 2021/12/16 18:43:07 UTC

svn commit: r1896070 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java

Author: tilman
Date: Thu Dec 16 18:43:07 2021
New Revision: 1896070

URL: http://svn.apache.org/viewvc?rev=1896070&view=rev
Log:
PDFBOX-5345: use encryption dictionary length value, as suggested by Andreas Lehmkühler

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

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java?rev=1896070&r1=1896069&r2=1896070&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java Thu Dec 16 18:43:07 2021
@@ -177,15 +177,26 @@ public final class StandardSecurityHandl
                 {
                     dicLength = 128 / 8;
                     setAES(true);
+                    if (encryption.getCOSObject().containsKey(COSName.LENGTH))
+                    {
+                        // PDFBOX-5345
+                        int newLength = encryption.getLength() / 8;
+                        if (newLength < dicLength)
+                        {
+                            LOG.warn("Using " + newLength + " bytes key length instead of " +
+                                    dicLength + " in AESV2 encryption?!");
+                            dicLength = newLength;
+                        }
+                    }
                 }
                 if (COSName.AESV3.equals(cryptFilterMethod))
                 {
                     dicLength = 256 / 8;
                     setAES(true);
-                    if (stdCryptFilterDictionary.getCOSObject().containsKey(COSName.LENGTH))
+                    if (encryption.getCOSObject().containsKey(COSName.LENGTH))
                     {
                         // PDFBOX-5345
-                        int newLength = stdCryptFilterDictionary.getLength();
+                        int newLength = encryption.getLength() / 8;
                         if (newLength < dicLength)
                         {
                             LOG.warn("Using " + newLength + " bytes key length instead of " +