mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 10:08:06 +02:00
Prevent circular references in Type3 fonts
In corrupt PDF documents Type3 fonts may introduce circular dependencies, thus resulting in the affected font(s) never loading and parsing/rendering never completing. Note that I've not seen any real-world examples of this kind of font corruption, but the attached PDF document was rather found in https://github.com/pdf-association/safedocs/tree/main/Miscellaneous%20Targeted%20Test%20PDFs *Please note:* That repository contains a number of reduced test-cases that are specifically intended to test interoperability (between PDF viewer) and parsing/rendering for various kinds of strange/corrupt PDF documents. Some of the test-cases found there may thus not make sense to try and "fix" upfront, in my opinion, unless the problems are also found in real-world PDF documents.
This commit is contained in:
parent
ea57ef116e
commit
53d4ee7990
4 changed files with 139 additions and 0 deletions
|
@ -1155,6 +1155,10 @@ class PartialEvaluator {
|
|||
}
|
||||
}
|
||||
|
||||
if (this.parsingType3Font && this.type3FontRefs.has(fontRef)) {
|
||||
return errorFont();
|
||||
}
|
||||
|
||||
if (this.fontCache.has(fontRef)) {
|
||||
return this.fontCache.get(fontRef);
|
||||
}
|
||||
|
@ -4183,6 +4187,12 @@ class TranslatedFont {
|
|||
// make sense to only be able to render a Type3 glyph partially.
|
||||
const type3Evaluator = evaluator.clone({ ignoreErrors: false });
|
||||
type3Evaluator.parsingType3Font = true;
|
||||
// Prevent circular references in Type3 fonts.
|
||||
const type3FontRefs = new RefSet(evaluator.type3FontRefs);
|
||||
if (this.dict.objId && !type3FontRefs.has(this.dict.objId)) {
|
||||
type3FontRefs.put(this.dict.objId);
|
||||
}
|
||||
type3Evaluator.type3FontRefs = type3FontRefs;
|
||||
|
||||
const translatedFont = this.font,
|
||||
type3Dependencies = this.type3Dependencies;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue