From 403f44b32ad3fb92c293894ae5cdfea28be64103 Mon Sep 17 00:00:00 2001 From: Tilman Hausherr Date: Fri, 9 Aug 2024 15:37:48 +0000 Subject: [PATCH] PDFBOX-5866: also truncate the O and U entries, as suggested by Michael Klink git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1919783 13f79535-47bb-0310-9956-ffa450edef68 --- .../pdmodel/encryption/PDEncryption.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryption.java b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryption.java index 3a3c0a3d3a0..d356b20633e 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryption.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/PDEncryption.java @@ -277,6 +277,15 @@ public byte[] getOwnerKey() throws IOException if( owner != null ) { o = owner.getBytes(); + int r = getRevision(); + if (r <= 4) + { + o = Arrays.copyOf(o, 32); + } + else if (r == 6) + { + o = Arrays.copyOf(o, 48); + } } return o; } @@ -307,6 +316,15 @@ public byte[] getUserKey() throws IOException if( user != null ) { u = user.getBytes(); + int r = getRevision(); + if (r <= 4) + { + u = Arrays.copyOf(u, 32); + } + else if (r == 6) + { + u = Arrays.copyOf(u, 48); + } } return u; }