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:
parent
517ccb7a39
commit
4c54395ff6
@ -996,7 +996,7 @@ var CMapFactory = (function CMapFactoryClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
create(params) {
|
async create(params) {
|
||||||
var encoding = params.encoding;
|
var encoding = params.encoding;
|
||||||
var fetchBuiltInCMap = params.fetchBuiltInCMap;
|
var fetchBuiltInCMap = params.fetchBuiltInCMap;
|
||||||
var useCMap = params.useCMap;
|
var useCMap = params.useCMap;
|
||||||
@ -1015,7 +1015,7 @@ var CMapFactory = (function CMapFactoryClosure() {
|
|||||||
return parsedCMap;
|
return parsedCMap;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return Promise.reject(new Error("Encoding required."));
|
throw new Error("Encoding required.");
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
@ -2612,14 +2612,15 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
encoding: cmapObj,
|
encoding: cmapObj,
|
||||||
fetchBuiltInCMap: this.fetchBuiltInCMap,
|
fetchBuiltInCMap: this.fetchBuiltInCMap,
|
||||||
useCMap: null,
|
useCMap: null,
|
||||||
}).then(function(cmap) {
|
}).then(
|
||||||
|
function(cmap) {
|
||||||
if (cmap instanceof IdentityCMap) {
|
if (cmap instanceof IdentityCMap) {
|
||||||
return new IdentityToUnicodeMap(0, 0xffff);
|
return new IdentityToUnicodeMap(0, 0xffff);
|
||||||
}
|
}
|
||||||
var map = new Array(cmap.length);
|
var map = new Array(cmap.length);
|
||||||
// Convert UTF-16BE
|
// Convert UTF-16BE
|
||||||
// NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
|
// NOTE: cmap can be a sparse array, so use forEach instead of
|
||||||
// to iterate over all keys.
|
// `for(;;)` to iterate over all keys.
|
||||||
cmap.forEach(function(charCode, token) {
|
cmap.forEach(function(charCode, token) {
|
||||||
var str = [];
|
var str = [];
|
||||||
for (var k = 0; k < token.length; k += 2) {
|
for (var k = 0; k < token.length; k += 2) {
|
||||||
@ -2636,7 +2637,23 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
map[charCode] = String.fromCodePoint.apply(String, str);
|
map[charCode] = String.fromCodePoint.apply(String, str);
|
||||||
});
|
});
|
||||||
return new ToUnicodeMap(map);
|
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);
|
return Promise.resolve(null);
|
||||||
},
|
},
|
||||||
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -352,6 +352,7 @@
|
|||||||
!issue7878.pdf
|
!issue7878.pdf
|
||||||
!font_ascent_descent.pdf
|
!font_ascent_descent.pdf
|
||||||
!issue11442_reduced.pdf
|
!issue11442_reduced.pdf
|
||||||
|
!issue11549_reduced.pdf
|
||||||
!issue8097_reduced.pdf
|
!issue8097_reduced.pdf
|
||||||
!transparent.pdf
|
!transparent.pdf
|
||||||
!xobject-image.pdf
|
!xobject-image.pdf
|
||||||
|
BIN
test/pdfs/issue11549_reduced.pdf
Normal file
BIN
test/pdfs/issue11549_reduced.pdf
Normal file
Binary file not shown.
@ -60,6 +60,13 @@
|
|||||||
"link": false,
|
"link": false,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
},
|
||||||
|
{ "id": "issue11549",
|
||||||
|
"file": "pdfs/issue11549_reduced.pdf",
|
||||||
|
"md5": "a1ea636f413e02e10dbdf379ab4a99ae",
|
||||||
|
"rounds": 1,
|
||||||
|
"link": false,
|
||||||
|
"type": "eq"
|
||||||
|
},
|
||||||
{ "id": "issue1293",
|
{ "id": "issue1293",
|
||||||
"file": "pdfs/issue1293r.pdf",
|
"file": "pdfs/issue1293r.pdf",
|
||||||
"md5": "4a098f5051f34fab036f5bbe88f8deef",
|
"md5": "4a098f5051f34fab036f5bbe88f8deef",
|
||||||
|
Loading…
Reference in New Issue
Block a user