mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Convert UTF8 encoded passwords to ISO-8859-1 for |R = 6| encryption (issue 6010)
For passwords where the encoding already is correct, the conversion is a no-op. Also, since `encodeURIComponent` might throw, we need to make sure that we handle that case too. Fixes 6010.
This commit is contained in:
parent
90982332bf
commit
44240798be
6 changed files with 109 additions and 2 deletions
|
@ -15,7 +15,8 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
/* globals bytesToString, DecryptStream, error, isInt, isName, Name,
|
||||
PasswordException, PasswordResponses, stringToBytes */
|
||||
PasswordException, PasswordResponses, stringToBytes, warn,
|
||||
utf8StringToString */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
@ -1918,6 +1919,14 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
|
|||
var fileIdBytes = stringToBytes(fileId);
|
||||
var passwordBytes;
|
||||
if (password) {
|
||||
if (revision === 6) {
|
||||
try {
|
||||
password = utf8StringToString(password);
|
||||
} catch (ex) {
|
||||
warn('CipherTransformFactory: ' +
|
||||
'Unable to convert UTF8 encoded password.');
|
||||
}
|
||||
}
|
||||
passwordBytes = stringToBytes(password);
|
||||
}
|
||||
|
||||
|
@ -2022,7 +2031,7 @@ var CipherTransformFactory = (function CipherTransformFactoryClosure() {
|
|||
|
||||
CipherTransformFactory.prototype = {
|
||||
createCipherTransform:
|
||||
function CipherTransformFactory_createCipherTransform(num, gen) {
|
||||
function CipherTransformFactory_createCipherTransform(num, gen) {
|
||||
if (this.algorithm === 4 || this.algorithm === 5) {
|
||||
return new CipherTransform(
|
||||
buildCipherConstructor(this.cf, this.stmf,
|
||||
|
|
|
@ -946,6 +946,10 @@ function stringToUTF8String(str) {
|
|||
return decodeURIComponent(escape(str));
|
||||
}
|
||||
|
||||
function utf8StringToString(str) {
|
||||
return unescape(encodeURIComponent(str));
|
||||
}
|
||||
|
||||
function isEmptyObj(obj) {
|
||||
for (var key in obj) {
|
||||
return false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue