Skip to content

Commit

Permalink
Merge pull request #7493 from Snuffleupagus/issue-7492
Browse files Browse the repository at this point in the history
Catch errors and continue parsing in `parseCMap` (issue 7492)
  • Loading branch information
Snuffleupagus authored Jul 19, 2016
2 parents 0da97ad + 90d19de commit 9228a04
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 37 deletions.
81 changes: 44 additions & 37 deletions src/core/cmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@

var Util = sharedUtil.Util;
var assert = sharedUtil.assert;
var warn = sharedUtil.warn;
var error = sharedUtil.error;
var isInt = sharedUtil.isInt;
var isString = sharedUtil.isString;
var MissingDataException = sharedUtil.MissingDataException;
var isName = corePrimitives.isName;
var isCmd = corePrimitives.isCmd;
var isStream = corePrimitives.isStream;
Expand Down Expand Up @@ -881,41 +883,49 @@ var CMapFactory = (function CMapFactoryClosure() {
var previous;
var embededUseCMap;
objLoop: while (true) {
var obj = lexer.getObj();
if (isEOF(obj)) {
break;
} else if (isName(obj)) {
if (obj.name === 'WMode') {
parseWMode(cMap, lexer);
} else if (obj.name === 'CMapName') {
parseCMapName(cMap, lexer);
try {
var obj = lexer.getObj();
if (isEOF(obj)) {
break;
} else if (isName(obj)) {
if (obj.name === 'WMode') {
parseWMode(cMap, lexer);
} else if (obj.name === 'CMapName') {
parseCMapName(cMap, lexer);
}
previous = obj;
} else if (isCmd(obj)) {
switch (obj.cmd) {
case 'endcmap':
break objLoop;
case 'usecmap':
if (isName(previous)) {
embededUseCMap = previous.name;
}
break;
case 'begincodespacerange':
parseCodespaceRange(cMap, lexer);
break;
case 'beginbfchar':
parseBfChar(cMap, lexer);
break;
case 'begincidchar':
parseCidChar(cMap, lexer);
break;
case 'beginbfrange':
parseBfRange(cMap, lexer);
break;
case 'begincidrange':
parseCidRange(cMap, lexer);
break;
}
}
previous = obj;
} else if (isCmd(obj)) {
switch (obj.cmd) {
case 'endcmap':
break objLoop;
case 'usecmap':
if (isName(previous)) {
embededUseCMap = previous.name;
}
break;
case 'begincodespacerange':
parseCodespaceRange(cMap, lexer);
break;
case 'beginbfchar':
parseBfChar(cMap, lexer);
break;
case 'begincidchar':
parseCidChar(cMap, lexer);
break;
case 'beginbfrange':
parseBfRange(cMap, lexer);
break;
case 'begincidrange':
parseCidRange(cMap, lexer);
break;
} catch (ex) {
if (ex instanceof MissingDataException) {
throw ex;
}
warn('Invalid cMap data: ' + ex);
continue;
}
}

Expand All @@ -926,9 +936,8 @@ var CMapFactory = (function CMapFactoryClosure() {
}
if (useCMap) {
return extendCMap(cMap, builtInCMapParams, useCMap);
} else {
return Promise.resolve(cMap);
}
return Promise.resolve(cMap);
}

function extendCMap(cMap, builtInCMapParams, useCMap) {
Expand Down Expand Up @@ -990,8 +999,6 @@ var CMapFactory = (function CMapFactoryClosure() {
parseCMap(cMap, lexer, builtInCMapParams, null).then(
function (parsedCMap) {
resolve(parsedCMap);
}).catch(function (e) {
reject(new Error({ message: 'Invalid CMap data', error: e }));
});
} else {
reject(new Error('Unable to get cMap at: ' + url));
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
!issue7200.pdf
!issue7229.pdf
!issue7439.pdf
!issue7492.pdf
!filled-background.pdf
!ArabicCIDTrueType.pdf
!ThuluthFeatures.pdf
Expand Down
Binary file added test/pdfs/issue7492.pdf
Binary file not shown.
14 changes: 14 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,20 @@
"link": false,
"type": "eq"
},
{ "id": "issue7492-eq",
"file": "pdfs/issue7492.pdf",
"md5": "7b0b28919c1088a2a5a0aeedbaa4c3ca",
"rounds": 1,
"link": false,
"type": "eq"
},
{ "id": "issue7492-text",
"file": "pdfs/issue7492.pdf",
"md5": "7b0b28919c1088a2a5a0aeedbaa4c3ca",
"rounds": 1,
"link": false,
"type": "text"
},
{ "id": "ShowText-ShadingPattern",
"file": "pdfs/ShowText-ShadingPattern.pdf",
"md5": "fe683725db037ffe19d390969610a652",
Expand Down

0 comments on commit 9228a04

Please sign in to comment.