Allow skipping of errors when reading broken/corrupt ToUnicode data (issue 11549)

This will allow font loading/parsing to continue, rather than immediately failing, when broken/corrupt CMap data is encountered.
This commit is contained in:
Jonas Jenwald 2020-01-30 13:13:51 +01:00
parent 517ccb7a39
commit 4c54395ff6
5 changed files with 51 additions and 26 deletions

View File

@ -996,7 +996,7 @@ var CMapFactory = (function CMapFactoryClosure() {
}
return {
create(params) {
async create(params) {
var encoding = params.encoding;
var fetchBuiltInCMap = params.fetchBuiltInCMap;
var useCMap = params.useCMap;
@ -1015,7 +1015,7 @@ var CMapFactory = (function CMapFactoryClosure() {
return parsedCMap;
});
}
return Promise.reject(new Error("Encoding required."));
throw new Error("Encoding required.");
},
};
})();

View File

@ -2612,31 +2612,48 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
encoding: cmapObj,
fetchBuiltInCMap: this.fetchBuiltInCMap,
useCMap: null,
}).then(function(cmap) {
if (cmap instanceof IdentityCMap) {
return new IdentityToUnicodeMap(0, 0xffff);
}
var map = new Array(cmap.length);
// Convert UTF-16BE
// NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
// to iterate over all keys.
cmap.forEach(function(charCode, token) {
var str = [];
for (var k = 0; k < token.length; k += 2) {
var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
if ((w1 & 0xf800) !== 0xd800) {
// w1 < 0xD800 || w1 > 0xDFFF
str.push(w1);
continue;
}
k += 2;
var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
}).then(
function(cmap) {
if (cmap instanceof IdentityCMap) {
return new IdentityToUnicodeMap(0, 0xffff);
}
map[charCode] = String.fromCodePoint.apply(String, str);
});
return new ToUnicodeMap(map);
});
var map = new Array(cmap.length);
// Convert UTF-16BE
// NOTE: cmap can be a sparse array, so use forEach instead of
// `for(;;)` to iterate over all keys.
cmap.forEach(function(charCode, token) {
var str = [];
for (var k = 0; k < token.length; k += 2) {
var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
if ((w1 & 0xf800) !== 0xd800) {
// w1 < 0xD800 || w1 > 0xDFFF
str.push(w1);
continue;
}
k += 2;
var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
}
map[charCode] = String.fromCodePoint.apply(String, str);
});
return new ToUnicodeMap(map);
},
reason => {
if (reason instanceof AbortException) {
return null;
}
if (this.options.ignoreErrors) {
// Error in the ToUnicode data -- sending unsupported feature
// notification and allow font parsing to continue.
this.handler.send("UnsupportedFeature", {
featureId: UNSUPPORTED_FEATURES.font,
});
warn(`readToUnicode - ignoring ToUnicode data: "${reason}".`);
return null;
}
throw reason;
}
);
}
return Promise.resolve(null);
},

View File

@ -352,6 +352,7 @@
!issue7878.pdf
!font_ascent_descent.pdf
!issue11442_reduced.pdf
!issue11549_reduced.pdf
!issue8097_reduced.pdf
!transparent.pdf
!xobject-image.pdf

Binary file not shown.

View File

@ -60,6 +60,13 @@
"link": false,
"type": "eq"
},
{ "id": "issue11549",
"file": "pdfs/issue11549_reduced.pdf",
"md5": "a1ea636f413e02e10dbdf379ab4a99ae",
"rounds": 1,
"link": false,
"type": "eq"
},
{ "id": "issue1293",
"file": "pdfs/issue1293r.pdf",
"md5": "4a098f5051f34fab036f5bbe88f8deef",