Skip to content

Commit

Permalink
Pad rev 4 encryption keys to be >= 16 bytes. Fixes issue #19484.
Browse files Browse the repository at this point in the history
  • Loading branch information
rossj committed Feb 24, 2025
1 parent fef7062 commit 63f2084
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/core/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,14 @@ class CipherTransformFactory {
);
}

this.encryptionKey = encryptionKey;
if (algorithm >= 4 && encryptionKey.length < 16) {
// Extend key to 16 byte minimum (undocumented)
// Fixes issue19484_1.pdf & issue19484_2.pdf
this.encryptionKey = new Uint8Array(16);
this.encryptionKey.set(encryptionKey);
} else {
this.encryptionKey = encryptionKey;
}

if (algorithm >= 4) {
const cf = dict.get("CF");
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/issue19484_1.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/user-attachments/files/18788789/R.4.V.4.40-bit.RC4.pdf
1 change: 1 addition & 0 deletions test/pdfs/issue19484_2.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/user-attachments/files/18788788/R.4.V.4.48-bit.RC4.pdf
16 changes: 16 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3629,6 +3629,14 @@
"link": false,
"type": "text"
},
{
"id": "issue19484_1",
"file": "pdfs/issue19484_1.pdf",
"md5": "4e9e78a84226dbdddbd735388ccc2dcd",
"rounds": 1,
"link": true,
"type": "eq"
},
{
"id": "issue5644",
"file": "pdfs/issue5644.pdf",
Expand Down Expand Up @@ -5043,6 +5051,14 @@
"rounds": 1,
"type": "eq"
},
{
"id": "issue19484_2",
"file": "pdfs/issue19484_2.pdf",
"md5": "cd3050eda9fa18a7e6a78c702f9890bb",
"rounds": 1,
"link": true,
"type": "eq"
},
{
"id": "bug894572",
"file": "pdfs/bug894572.pdf",
Expand Down

0 comments on commit 63f2084

Please sign in to comment.