Skip to content

Commit

Permalink
Merge pull request #9044 from brendandahl/plain-text-charstring
Browse files Browse the repository at this point in the history
Use charstring as plain text when lengthIV is -1.
  • Loading branch information
Snuffleupagus committed Oct 19, 2017
2 parents 4c384e1 + fcc9943 commit 56c14e2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/core/type1_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ var Type1CharString = (function Type1CharStringClosure() {
break;
}
subrNumber = this.stack.pop();
if (!subrs[subrNumber]) {
error = true;
break;
}
error = this.convert(subrs[subrNumber], subrs,
seacAnalysisEnabled);
break;
Expand Down Expand Up @@ -503,6 +507,15 @@ var Type1Parser = (function Type1ParserClosure() {
return token;
},

readCharStrings: function Type1Parser_readCharStrings(bytes, lenIV) {
if (lenIV === -1) {
// This isn't in the spec, but Adobe's tx program handles -1
// as plain text.
return bytes;
}
return decrypt(bytes, CHAR_STRS_ENCRYPT_KEY, lenIV);
},

/*
* Returns an object containing a Subrs array and a CharStrings
* array extracted from and eexec encrypted block of data
Expand Down Expand Up @@ -548,7 +561,7 @@ var Type1Parser = (function Type1ParserClosure() {
this.getToken(); // read in 'RD' or '-|'
data = stream.makeSubStream(stream.pos, length);
lenIV = program.properties.privateData['lenIV'];
encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
encoded = this.readCharStrings(data.getBytes(), lenIV);
// Skip past the required space and binary data.
stream.skip(length);
this.nextChar();
Expand All @@ -571,7 +584,7 @@ var Type1Parser = (function Type1ParserClosure() {
this.getToken(); // read in 'RD' or '-|'
data = stream.makeSubStream(stream.pos, length);
lenIV = program.properties.privateData['lenIV'];
encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
encoded = this.readCharStrings(data.getBytes(), lenIV);
// Skip past the required space and binary data.
stream.skip(length);
this.nextChar();
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
!issue7101.pdf
!issue7115.pdf
!issue7180.pdf
!issue7769.pdf
!issue7200.pdf
!issue7229.pdf
!issue7403.pdf
Expand Down
Binary file added test/pdfs/issue7769.pdf
Binary file not shown.
7 changes: 7 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,13 @@
"link": false,
"type": "eq"
},
{ "id": "issue7769",
"file": "pdfs/issue7769.pdf",
"md5": "814f167b8437eb8e4e4b6e89743011d5",
"rounds": 1,
"link": false,
"type": "eq"
},
{ "id": "issue5044",
"file": "pdfs/issue5044.pdf",
"md5": "44788cd31dcb4a2495ded34a84c4a765",
Expand Down

0 comments on commit 56c14e2

Please sign in to comment.