Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 2, 2021

Conversation

calixteman
Copy link
Contributor

No description provided.

@calixteman
Copy link
Contributor Author

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Sep 1, 2021

From: Bot.io (Windows)


Received

Command cmd_test from @calixteman received. Current queue size: 0

Live output at: http://3.101.106.178:8877/72618ade8d68d34/output.txt

@timvandermeij
Copy link
Contributor

timvandermeij commented Sep 1, 2021

Would it be possible to add a unit test for this since this is core functionality? This particular function can be called with the input that failed before and there is even a helper function that asserts that it can also be decoded again:

function ensureEncryptDecryptIsIdentity(dict, fileId, password, string) {
const factory = new CipherTransformFactory(dict, fileId, password);
const cipher = factory.createCipherTransform(123, 0);
const encrypted = cipher.encryptString(string);
const decrypted = cipher.decryptString(encrypted);
expect(string).toEqual(decrypted);
}

Something like this make work here since the code path in this PR is limited to AES:

it("should encrypt and decrypt using AES256", function () {
dict3.CF = buildDict({
Identity: buildDict({
CFM: Name.get("AESV3"),
}),
});
const dict = buildDict(dict3);
// 4 chars
ensureEncryptDecryptIsIdentity(dict, fileId1, "user", "aaaa");
// 5 chars
ensureEncryptDecryptIsIdentity(dict, fileId1, "user", "aaaaa");
// 16 chars
ensureEncryptDecryptIsIdentity(dict, fileId1, "user", "aaaaaaaaaaaaaaaa");
// 22 chars
ensureEncryptDecryptIsIdentity(
dict,
fileId1,
"user",
"aaaaaaaaaaaaaaaaaaaaaa"
);
});
});

@calixteman
Copy link
Contributor Author

Before the patch, pdf.js, evince, mupdf and qpdf were able to decrypt correctly the string but not foxit, chrome and acrobat.
There is already a test with a string where length is a multiple of 16 (e.g. https://github.com/mozilla/pdf.js/blob/master/test/unit/crypto_spec.js#L836).
So I don't see how to have a test which fails without the patch, any idea will be appreciated.

@pdfjsbot
Copy link

pdfjsbot commented Sep 1, 2021

From: Bot.io (Windows)


Failed

Full output at http://3.101.106.178:8877/72618ade8d68d34/output.txt

Total script time: 39.76 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Integration Tests: Passed
  • Regression tests: FAILED
  different ref/snapshot: 28
  different first/second rendering: 1

Image differences available at: http://3.101.106.178:8877/72618ade8d68d34/reftest-analyzer.html#web=eq.log

@calixteman
Copy link
Contributor Author

/botio unittest

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2021

From: Bot.io (Windows)


Received

Command cmd_unittest from @calixteman received. Current queue size: 0

Live output at: http://3.101.106.178:8877/7bcb7f6b44dd480/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2021

From: Bot.io (Linux m4)


Received

Command cmd_unittest from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/6b12066d178e9eb/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2021

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/6b12066d178e9eb/output.txt

Total script time: 2.74 mins

  • Unit Tests: Passed

@pdfjsbot
Copy link

pdfjsbot commented Sep 2, 2021

From: Bot.io (Windows)


Success

Full output at http://3.101.106.178:8877/7bcb7f6b44dd480/output.txt

Total script time: 5.43 mins

  • Unit Tests: Passed

@brendandahl brendandahl merged commit 804abb3 into mozilla:master Sep 2, 2021
@timvandermeij timvandermeij removed the request for review from brendandahl September 4, 2021 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants