Skip to content

Commit 57b9978

Browse files
committed
PDFBOX-6115: rethrow IllegalArgumentException as IOException
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930246 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1c7930e commit 57b9978

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -945,24 +945,32 @@ public byte[] computeOwnerPassword(byte[] ownerPassword, byte[] userPassword,
945945
}
946946

947947
// steps (a) to (d) of "Algorithm 3: Computing the encryption dictionary’s O (owner password) value".
948-
private byte[] computeRC4key(byte[] ownerPassword, int encRevision, int length)
948+
private byte[] computeRC4key(byte[] ownerPassword, int encRevision, int length) throws IOException
949949
{
950-
MessageDigest md = MessageDigests.getMD5();
951-
byte[] digest = md.digest(truncateOrPad(ownerPassword));
952-
if (encRevision == REVISION_3 || encRevision == REVISION_4)
950+
try
953951
{
954-
for (int i = 0; i < 50; i++)
952+
MessageDigest md = MessageDigests.getMD5();
953+
byte[] digest = md.digest(truncateOrPad(ownerPassword));
954+
if (encRevision == REVISION_3 || encRevision == REVISION_4)
955955
{
956-
// this deviates from the spec - however, omitting the length
957-
// parameter prevents the file to be opened in Adobe Reader
958-
// with the owner password when the key length is 40 bit (= 5 bytes)
959-
md.update(digest, 0, length);
960-
digest = md.digest();
956+
for (int i = 0; i < 50; i++)
957+
{
958+
// this deviates from the spec - however, omitting the length
959+
// parameter prevents the file to be opened in Adobe Reader
960+
// with the owner password when the key length is 40 bit (= 5 bytes)
961+
md.update(digest, 0, length);
962+
digest = md.digest();
963+
}
961964
}
965+
byte[] rc4Key = new byte[length];
966+
System.arraycopy(digest, 0, rc4Key, 0, length);
967+
return rc4Key;
968+
}
969+
catch (IllegalArgumentException ex)
970+
{
971+
// PDFBOX-6115: happens with illegal key length
972+
throw new IOException(ex);
962973
}
963-
byte[] rc4Key = new byte[length];
964-
System.arraycopy(digest, 0, rc4Key, 0, length);
965-
return rc4Key;
966974
}
967975

968976

0 commit comments

Comments
 (0)