Skip to content

Commit 463b182

Browse files
committed
Correctly pad strings when saving an encrypted pdf (bug 1726789)
1 parent 2ed133b commit 463b182

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/core/crypto.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1407,11 +1407,12 @@ class CipherTransform {
14071407
// Append some chars equal to "16 - (M mod 16)"
14081408
// where M is the string length (see section 7.6.2 in PDF specification)
14091409
// to have a final string where the length is a multiple of 16.
1410+
// Special note:
1411+
// "Note that the pad is present when M is evenly divisible by 16;
1412+
// it contains 16 bytes of 0x10."
14101413
const strLen = s.length;
14111414
const pad = 16 - (strLen % 16);
1412-
if (pad !== 16) {
1413-
s = s.padEnd(16 * Math.ceil(strLen / 16), String.fromCharCode(pad));
1414-
}
1415+
s += String.fromCharCode(pad).repeat(pad);
14151416

14161417
// Generate an initialization vector
14171418
const iv = new Uint8Array(16);

0 commit comments

Comments
 (0)