1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Merge pull request #13959 from calixteman/encrypt

Correctly pad strings when saving an encrypted pdf (bug 1726789)
This commit is contained in:
Brendan Dahl 2021-09-02 11:41:02 -07:00 committed by GitHub
commit 804abb3786
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 88 additions and 3 deletions

View file

@ -1407,11 +1407,12 @@ class CipherTransform {
// Append some chars equal to "16 - (M mod 16)"
// where M is the string length (see section 7.6.2 in PDF specification)
// to have a final string where the length is a multiple of 16.
// Special note:
// "Note that the pad is present when M is evenly divisible by 16;
// it contains 16 bytes of 0x10."
const strLen = s.length;
const pad = 16 - (strLen % 16);
if (pad !== 16) {
s = s.padEnd(16 * Math.ceil(strLen / 16), String.fromCharCode(pad));
}
s += String.fromCharCode(pad).repeat(pad);
// Generate an initialization vector
const iv = new Uint8Array(16);