Author: tilman
Date: Thu Dec 4 10:37:25 2025
New Revision: 1930246
Log:
PDFBOX-6115: rethrow IllegalArgumentException as IOException
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
==============================================================================
---
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
Thu Dec 4 10:37:21 2025 (r1930245)
+++
pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
Thu Dec 4 10:37:25 2025 (r1930246)
@@ -945,24 +945,32 @@ public final class StandardSecurityHandl
}
// steps (a) to (d) of "Algorithm 3: Computing the encryption dictionary’s
O (owner password) value".
- private byte[] computeRC4key(byte[] ownerPassword, int encRevision, int
length)
+ private byte[] computeRC4key(byte[] ownerPassword, int encRevision, int
length) throws IOException
{
- MessageDigest md = MessageDigests.getMD5();
- byte[] digest = md.digest(truncateOrPad(ownerPassword));
- if (encRevision == REVISION_3 || encRevision == REVISION_4)
+ try
{
- for (int i = 0; i < 50; i++)
+ MessageDigest md = MessageDigests.getMD5();
+ byte[] digest = md.digest(truncateOrPad(ownerPassword));
+ if (encRevision == REVISION_3 || encRevision == REVISION_4)
{
- // this deviates from the spec - however, omitting the length
- // parameter prevents the file to be opened in Adobe Reader
- // with the owner password when the key length is 40 bit (= 5
bytes)
- md.update(digest, 0, length);
- digest = md.digest();
+ for (int i = 0; i < 50; i++)
+ {
+ // this deviates from the spec - however, omitting the
length
+ // parameter prevents the file to be opened in Adobe Reader
+ // with the owner password when the key length is 40 bit
(= 5 bytes)
+ md.update(digest, 0, length);
+ digest = md.digest();
+ }
}
+ byte[] rc4Key = new byte[length];
+ System.arraycopy(digest, 0, rc4Key, 0, length);
+ return rc4Key;
+ }
+ catch (IllegalArgumentException ex)
+ {
+ // PDFBOX-6115: happens with illegal key length
+ throw new IOException(ex);
}
- byte[] rc4Key = new byte[length];
- System.arraycopy(digest, 0, rc4Key, 0, length);
- return rc4Key;
}