1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 01:58:06 +02:00

Correctly pad strings when saving an encrypted pdf (bug 1726789)

This commit is contained in:
Calixte Denizet 2021-09-01 21:55:21 +02:00
parent 2ed133bd99
commit 9619bf92be
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);