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:
Jonas Jenwald 2015-05-13 17:25:42 +02:00
parent 90982332bf
commit 44240798be
6 changed files with 109 additions and 2 deletions

View File

@ -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,

View File

@ -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;

View File

@ -130,3 +130,5 @@
!issue5701.pdf
!issue5896.pdf
!issue5909.pdf
!issue6010_1.pdf
!issue6010_2.pdf

37
test/pdfs/issue6010_1.pdf Normal file
View File

@ -0,0 +1,37 @@
%PDF-1.7
%€<>ƒ
1 0 obj
<</Pages 6 0 R/Type/Catalog>>
endobj
2 0 obj
<</Type/Encoding/BaseEncoding/WinAnsiEncoding>>
endobj
3 0 obj
<</Parent 6 0 R/Resources<</Font<</F1 5 0 R>>>>/MediaBox[0 0 200 50]/Type/Page/Contents 4 0 R>>
endobj
4 0 obj
<</Filter/FlateDecode/Length 64>>
stream
‚Õ6<>2ˆÖõ|Q$j¾•ƒ¯^BHJC<wß²ÆM%X33uì°º;½*¡¬iÍ»ÄÞöKöÏ9³¦­IRñ
endstream
endobj
5 0 obj
<</BaseFont/Times-Roman/Subtype/Type1/Type/Font/Encoding 2 0 R>>
endobj
6 0 obj
<</MediaBox[0 0 200 50]/Kids[3 0 R]/Type/Pages/Count 1>>
endobj
xref
0 7
0000000000 65535 f
0000000015 00000 n
0000000060 00000 n
0000000123 00000 n
0000000234 00000 n
0000000365 00000 n
0000000445 00000 n
trailer
<</Size 7/ID[(gUe>/j¿_ƒ8:)(gUe>/j¿_ƒ8:)]/Encrypt<</Filter/Standard/V 5/CF<</StdCF<</Length 32/AuthEvent/DocOpen/CFM/AESV3>>>>/EncryptMetadata true/Length 256/R 6/O(éô6âÖ\(«T#¸óƒ‰<C692>k6PQéŽ\nšèã`@”µ$ï¾Kþë<C3BE>eÀù F„â)/U(ïéË 4É4õš~>W…nT-û:„Æø}|XSvf2,^—,ê}w£‡3\fÜÝý<07>)/P -4/StrF/StdCF/StmF/StdCF/Perms(×ìÀï§\réou)/OE(Å?ÑOƒ<4F>ëæ<C3AB>\(Q¸5F ýéRVÆJÒÿ,VYö)/UE(Ebîlp·KÃ5±PL­ÜúÉFqIöD<<3C>€>ø<ô)>>/Root 1 0 R>>
startxref
517
%%EOF

38
test/pdfs/issue6010_2.pdf Normal file
View File

@ -0,0 +1,38 @@
%PDF-1.7
%€<>ƒ
1 0 obj
<</Pages 6 0 R/Type/Catalog>>
endobj
2 0 obj
<</Type/Encoding/BaseEncoding/WinAnsiEncoding>>
endobj
3 0 obj
<</Parent 6 0 R/Resources<</Font<</F1 5 0 R>>>>/MediaBox[0 0 200 50]/Type/Page/Contents 4 0 R>>
endobj
4 0 obj
<</Filter/FlateDecode/Length 64>>
stream
Ùä±hºR™$£<11>ãÖ¯Õk<>ño¨ÎoElg, Ž<>Qhw$YvÃ=Ý;^êuÖêsÃ_ï
##%„'§ð
endstream
endobj
5 0 obj
<</BaseFont/Times-Roman/Subtype/Type1/Type/Font/Encoding 2 0 R>>
endobj
6 0 obj
<</MediaBox[0 0 200 50]/Kids[3 0 R]/Type/Pages/Count 1>>
endobj
xref
0 7
0000000000 65535 f
0000000015 00000 n
0000000060 00000 n
0000000123 00000 n
0000000234 00000 n
0000000365 00000 n
0000000445 00000 n
trailer
<</Size 7/ID[(I†$"E6?TÓ™nß<6E>\b)(I†$"E6?TÓ™nß<6E>\b)]/Encrypt<</Filter/Standard/V 5/CF<</StdCF<</Length 32/AuthEvent/DocOpen/CFM/AESV3>>>>/EncryptMetadata true/Length 256/R 6/O( ë“·XXB\f¢ôÞp ñG&§Â§q0Ò<¼Ÿã¾Px<50>a¸U·ý¤<E28098>À½Y)/U(WPkþD£¹_ÃŒL^—·ÃD\f.CÝs·rÌÃöF\\NU¿±L¸ ¨µ4¦Ð9Ü)/P -4/StrF/StdCF/StmF/StdCF/Perms( G^´o¯¢ÜöF‰GQO)/OE(h7饷óâ´<C3A2>Cn˜çóx¤·ˆ¦¾åÐ'7+Ž<>n53€E)/UE(žW€[‰ZѪ=Q©¥¨Ç0y…#Ü#ôÔ­ý&Ú¹£ÙPv)>>/Root 1 0 R>>
startxref
517
%%EOF

View File

@ -1493,6 +1493,23 @@
"type": "eq",
"about": "Rotated transparency group with blend mode."
},
{ "id": "issue6010_1",
"file": "pdfs/issue6010_1.pdf",
"md5": "b58adce5dbb08936ddb0d904f0da8716",
"rounds": 1,
"link": false,
"type": "load",
"password": "abc"
},
{ "id": "issue6010_2",
"file": "pdfs/issue6010_2.pdf",
"md5": "73a8091d0ab2a47af5ca45047f04da99",
"rounds": 1,
"link": false,
"type": "load",
"password": "\u00E6\u00F8\u00E5",
"about": "The password (æøå) is UTF8 encoded."
},
{ "id": "issue3458.pdf",
"file": "pdfs/issue3458.pdf",
"md5": "dab8bd3ad1acfc8dc82a8381a3c8ff94",