Martin Mirchev created PDFBOX-6329:
--------------------------------------
Summary: NullPointerException instead of IOException when the
encryption dictionary has no /U or /O entry
Key: PDFBOX-6329
URL: https://issues.apache.org/jira/browse/PDFBOX-6329
Project: PDFBox
Issue Type: Bug
Components: Crypto
Affects Versions: 4.0.0, 3.0.8 PDFBox
Reporter: Martin Mirchev
Attachments: r2-no-o.pdf, r2-no-u.pdf, r4-no-o.pdf, r4-no-u.pdf,
r6-no-o.pdf, r6-no-u.pdf, r6-ok.pdf
{{StandardSecurityHandler.prepareForDecryption()}} passes
{{encryption.getUserKey()}} and {{encryption.getOwnerKey()}} to the password
checks without checking that the entries exist. When a Standard security
handler dictionary lacks {{/U}} or {{/O}} (both are required),
{{Loader.loadPDF()}} throws a {{NullPointerException}} for every revision, with
or without a password, instead of an {{IOException}}:
{code}
/U missing, R2/R3/R4: java.lang.NullPointerException: Cannot read the array
length because "original" is null
at
org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.isUserPassword234(StandardSecurityHandler.java:1044)
/U missing, R6: java.lang.NullPointerException
at java.base/java.lang.System.arraycopy(Native Method)
at
org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.isUserPassword56(StandardSecurityHandler.java:1053)
/O missing, R2/R3/R4: java.lang.NullPointerException: Cannot read the array
length because "owner" is null
at
org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.getUserPassword234(StandardSecurityHandler.java:687)
/O missing, R6: java.lang.NullPointerException: Cannot read the array
length because "owner" is null
at
org.apache.pdfbox.pdmodel.encryption.StandardSecurityHandler.isOwnerPassword56(StandardSecurityHandler.java:624)
{code}
The attached files were saved by PDFBox itself with
{{StandardProtectionPolicy}} (40-, 128- and 256-bit keys, owner password
"owner", empty user password); in each, the {{/U}} or {{/O}} entry was blanked
out with spaces so that the offsets stay valid. {{r6-ok.pdf}} is the unmodified
256-bit file and opens normally. Each result was the same in 3 runs.
A possible change, in the style of the existing "/Encrypt/UE entry is missing"
check; with it, all six files fail with an {{IOException}} naming the missing
entry and {{r6-ok.pdf}} still opens:
{code}
---
a/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
+++
b/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/encryption/StandardSecurityHandler.java
@@ -232,6 +232,14 @@
byte[] userKey = encryption.getUserKey();
byte[] ownerKey = encryption.getOwnerKey();
+ if (userKey == null)
+ {
+ throw new IOException("/Encrypt/U entry is missing");
+ }
+ if (ownerKey == null)
+ {
+ throw new IOException("/Encrypt/O entry is missing");
+ }
byte[] ue = null, oe = null;
Charset passwordCharset = StandardCharsets.ISO_8859_1;
{code}
This issue was found by an LLM-assisted tool and verified manually.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]