mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-08 08:05:49 +02:00
Avoid cycles when getting operator list in patterns
This commit is contained in:
parent
a5e9940d14
commit
29fcf0aa76
@ -982,7 +982,8 @@ class PartialEvaluator {
|
|||||||
patternDict,
|
patternDict,
|
||||||
operatorList,
|
operatorList,
|
||||||
task,
|
task,
|
||||||
localTilingPatternCache
|
localTilingPatternCache,
|
||||||
|
seenRefs
|
||||||
) {
|
) {
|
||||||
// Create an IR of the pattern code.
|
// Create an IR of the pattern code.
|
||||||
const tilingOpList = new CheckedOperatorList();
|
const tilingOpList = new CheckedOperatorList();
|
||||||
@ -998,6 +999,7 @@ class PartialEvaluator {
|
|||||||
task,
|
task,
|
||||||
resources: patternResources,
|
resources: patternResources,
|
||||||
operatorList: tilingOpList,
|
operatorList: tilingOpList,
|
||||||
|
prevRefs: seenRefs,
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
const operatorListIR = tilingOpList.getIR();
|
const operatorListIR = tilingOpList.getIR();
|
||||||
@ -1041,7 +1043,8 @@ class PartialEvaluator {
|
|||||||
task,
|
task,
|
||||||
state,
|
state,
|
||||||
fallbackFontDict = null,
|
fallbackFontDict = null,
|
||||||
cssFontInfo = null
|
cssFontInfo = null,
|
||||||
|
seenRefs = null
|
||||||
) {
|
) {
|
||||||
const fontName = fontArgs?.[0] instanceof Name ? fontArgs[0].name : null;
|
const fontName = fontArgs?.[0] instanceof Name ? fontArgs[0].name : null;
|
||||||
|
|
||||||
@ -1051,7 +1054,8 @@ class PartialEvaluator {
|
|||||||
resources,
|
resources,
|
||||||
task,
|
task,
|
||||||
fallbackFontDict,
|
fallbackFontDict,
|
||||||
cssFontInfo
|
cssFontInfo,
|
||||||
|
seenRefs
|
||||||
);
|
);
|
||||||
|
|
||||||
if (translated.font.isType3Font) {
|
if (translated.font.isType3Font) {
|
||||||
@ -1152,7 +1156,10 @@ class PartialEvaluator {
|
|||||||
value[0],
|
value[0],
|
||||||
operatorList,
|
operatorList,
|
||||||
task,
|
task,
|
||||||
stateManager.state
|
stateManager.state,
|
||||||
|
/* fallbackFontDict = */ null,
|
||||||
|
/* cssFontInfo = */ null,
|
||||||
|
seenRefs
|
||||||
).then(function (loadedName) {
|
).then(function (loadedName) {
|
||||||
operatorList.addDependency(loadedName);
|
operatorList.addDependency(loadedName);
|
||||||
gStateObj.push([key, [loadedName, value[1]]]);
|
gStateObj.push([key, [loadedName, value[1]]]);
|
||||||
@ -1230,7 +1237,8 @@ class PartialEvaluator {
|
|||||||
resources,
|
resources,
|
||||||
task,
|
task,
|
||||||
fallbackFontDict = null,
|
fallbackFontDict = null,
|
||||||
cssFontInfo = null
|
cssFontInfo = null,
|
||||||
|
seenRefs = null
|
||||||
) {
|
) {
|
||||||
const errorFont = async () =>
|
const errorFont = async () =>
|
||||||
new TranslatedFont({
|
new TranslatedFont({
|
||||||
@ -1366,7 +1374,7 @@ class PartialEvaluator {
|
|||||||
|
|
||||||
if (translatedFont.isType3Font) {
|
if (translatedFont.isType3Font) {
|
||||||
try {
|
try {
|
||||||
await translated.loadType3Data(this, resources, task);
|
await translated.loadType3Data(this, resources, task, seenRefs);
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
throw new Error(`Type3 font load error: ${reason}`);
|
throw new Error(`Type3 font load error: ${reason}`);
|
||||||
}
|
}
|
||||||
@ -1577,7 +1585,8 @@ class PartialEvaluator {
|
|||||||
task,
|
task,
|
||||||
localColorSpaceCache,
|
localColorSpaceCache,
|
||||||
localTilingPatternCache,
|
localTilingPatternCache,
|
||||||
localShadingPatternCache
|
localShadingPatternCache,
|
||||||
|
seenRefs
|
||||||
) {
|
) {
|
||||||
// compile tiling patterns
|
// compile tiling patterns
|
||||||
const patternName = args.pop();
|
const patternName = args.pop();
|
||||||
@ -1619,7 +1628,8 @@ class PartialEvaluator {
|
|||||||
dict,
|
dict,
|
||||||
operatorList,
|
operatorList,
|
||||||
task,
|
task,
|
||||||
localTilingPatternCache
|
localTilingPatternCache,
|
||||||
|
seenRefs
|
||||||
);
|
);
|
||||||
} else if (typeNum === PatternType.SHADING) {
|
} else if (typeNum === PatternType.SHADING) {
|
||||||
const shading = dict.get("Shading");
|
const shading = dict.get("Shading");
|
||||||
@ -1934,7 +1944,9 @@ class PartialEvaluator {
|
|||||||
operatorList,
|
operatorList,
|
||||||
task,
|
task,
|
||||||
stateManager.state,
|
stateManager.state,
|
||||||
fallbackFontDict
|
fallbackFontDict,
|
||||||
|
/* cssFontInfo = */ null,
|
||||||
|
seenRefs
|
||||||
)
|
)
|
||||||
.then(function (loadedName) {
|
.then(function (loadedName) {
|
||||||
operatorList.addDependency(loadedName);
|
operatorList.addDependency(loadedName);
|
||||||
@ -2112,7 +2124,8 @@ class PartialEvaluator {
|
|||||||
task,
|
task,
|
||||||
localColorSpaceCache,
|
localColorSpaceCache,
|
||||||
localTilingPatternCache,
|
localTilingPatternCache,
|
||||||
localShadingPatternCache
|
localShadingPatternCache,
|
||||||
|
seenRefs
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
@ -2144,7 +2157,8 @@ class PartialEvaluator {
|
|||||||
task,
|
task,
|
||||||
localColorSpaceCache,
|
localColorSpaceCache,
|
||||||
localTilingPatternCache,
|
localTilingPatternCache,
|
||||||
localShadingPatternCache
|
localShadingPatternCache,
|
||||||
|
seenRefs
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
@ -2731,7 +2745,10 @@ class PartialEvaluator {
|
|||||||
fontName,
|
fontName,
|
||||||
fontRef,
|
fontRef,
|
||||||
resources,
|
resources,
|
||||||
task
|
task,
|
||||||
|
/* fallbackFontDict = */ null,
|
||||||
|
/* cssFontInfo = */ null,
|
||||||
|
seenRefs
|
||||||
);
|
);
|
||||||
|
|
||||||
textState.loadedName = translated.loadedName;
|
textState.loadedName = translated.loadedName;
|
||||||
@ -4893,7 +4910,7 @@ class TranslatedFont {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadType3Data(evaluator, resources, task) {
|
loadType3Data(evaluator, resources, task, seenRefs = null) {
|
||||||
if (this.#type3Loaded) {
|
if (this.#type3Loaded) {
|
||||||
return this.#type3Loaded;
|
return this.#type3Loaded;
|
||||||
}
|
}
|
||||||
@ -4931,6 +4948,7 @@ class TranslatedFont {
|
|||||||
task,
|
task,
|
||||||
resources: fontResources,
|
resources: fontResources,
|
||||||
operatorList,
|
operatorList,
|
||||||
|
prevRefs: seenRefs,
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// According to the PDF specification, section "9.6.5 Type 3 Fonts"
|
// According to the PDF specification, section "9.6.5 Type 3 Fonts"
|
||||||
|
|||||||
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -912,3 +912,4 @@
|
|||||||
!smask_alpha_oob_transfer.pdf
|
!smask_alpha_oob_transfer.pdf
|
||||||
!smask_alpha_bc.pdf
|
!smask_alpha_bc.pdf
|
||||||
!smask_luminosity_oob_transfer.pdf
|
!smask_luminosity_oob_transfer.pdf
|
||||||
|
!operator_list_cycle.pdf
|
||||||
|
|||||||
98
test/pdfs/operator_list_cycle.pdf
Normal file
98
test/pdfs/operator_list_cycle.pdf
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
%PDF-1.7
|
||||||
|
% ò¤ô
|
||||||
|
1 0 obj <<
|
||||||
|
/Kids [3 0 R]
|
||||||
|
/Type /Pages
|
||||||
|
/Count 1
|
||||||
|
>>
|
||||||
|
endobj
|
||||||
|
2 0 obj <<
|
||||||
|
/Type /Catalog
|
||||||
|
/Pages 1 0 R
|
||||||
|
>>
|
||||||
|
endobj
|
||||||
|
3 0 obj <<
|
||||||
|
/Resources 11 0 R
|
||||||
|
/Type /Page
|
||||||
|
/Contents 10 0 R
|
||||||
|
/Parent 1 0 R
|
||||||
|
>>
|
||||||
|
endobj
|
||||||
|
10 0 obj <<
|
||||||
|
>>
|
||||||
|
stream
|
||||||
|
1 0 0 1 315.779 733.039 cm
|
||||||
|
1 0 0 1 2.835 -173.614 cm
|
||||||
|
1.04704 0 0 1.04704 0 0 cm
|
||||||
|
/Im6 Do
|
||||||
|
endstream
|
||||||
|
endobj
|
||||||
|
11 0 obj <<
|
||||||
|
/XObject <<
|
||||||
|
/Im6 12 0 R
|
||||||
|
>>
|
||||||
|
>>
|
||||||
|
endobj
|
||||||
|
12 0 obj <<
|
||||||
|
/Subtype /Form
|
||||||
|
/Resources <<
|
||||||
|
/XObject <<
|
||||||
|
/x15 13 0 R
|
||||||
|
>>
|
||||||
|
>>
|
||||||
|
>>
|
||||||
|
stream
|
||||||
|
/x15 Do
|
||||||
|
endstream
|
||||||
|
endobj
|
||||||
|
13 0 obj <<
|
||||||
|
/Subtype /Form
|
||||||
|
/Resources <<
|
||||||
|
/Pattern <<
|
||||||
|
/p31 14 0 R
|
||||||
|
>>
|
||||||
|
>>
|
||||||
|
>>
|
||||||
|
stream
|
||||||
|
q /Pattern cs /p31 scn /a0 gs
|
||||||
|
0 0 224.720001 160.399994 re f
|
||||||
|
Q
|
||||||
|
endstream
|
||||||
|
endobj
|
||||||
|
14 0 obj <<
|
||||||
|
/PatternType 1
|
||||||
|
/BBox [0 0 225 161]
|
||||||
|
/Resources <<
|
||||||
|
/XObject <<
|
||||||
|
/x47 12 0 R
|
||||||
|
>>
|
||||||
|
>>
|
||||||
|
>>
|
||||||
|
stream
|
||||||
|
/x47 Do
|
||||||
|
endstream
|
||||||
|
endobj
|
||||||
|
xref
|
||||||
|
0 15
|
||||||
|
0000000000 65535 f
|
||||||
|
4294967295 00000 n
|
||||||
|
0000000078 00000 n
|
||||||
|
0000000131 00000 n
|
||||||
|
0000000000 65535 f
|
||||||
|
0000000000 65535 f
|
||||||
|
0000000000 65535 f
|
||||||
|
0000000000 65535 f
|
||||||
|
0000000000 65535 f
|
||||||
|
0000000000 65535 f
|
||||||
|
0000000221 00000 n
|
||||||
|
0000000348 00000 n
|
||||||
|
0000000405 00000 n
|
||||||
|
0000000531 00000 n
|
||||||
|
0000000712 00000 n
|
||||||
|
trailer <<
|
||||||
|
/Root 2 0 R
|
||||||
|
/Size 110
|
||||||
|
>>
|
||||||
|
startxref
|
||||||
|
860
|
||||||
|
%%EOF
|
||||||
@ -4452,6 +4452,19 @@ have written that much by now. So, here’s to squashing bugs.`);
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
it("gets operator list, from a PDF with a Form -> Form -> Pattern -> Form cycle", async function () {
|
||||||
|
const loadingTask = getDocument(
|
||||||
|
buildGetDocumentParams("operator_list_cycle.pdf")
|
||||||
|
);
|
||||||
|
const pdfDoc = await loadingTask.promise;
|
||||||
|
const pdfPage = await pdfDoc.getPage(1);
|
||||||
|
|
||||||
|
const operatorList = await pdfPage.getOperatorList();
|
||||||
|
expect(operatorList.lastChunk).toEqual(true);
|
||||||
|
|
||||||
|
await loadingTask.destroy();
|
||||||
|
});
|
||||||
|
|
||||||
it("gets operator list, containing Annotation-operatorLists", async function () {
|
it("gets operator list, containing Annotation-operatorLists", async function () {
|
||||||
const loadingTask = getDocument(
|
const loadingTask = getDocument(
|
||||||
buildGetDocumentParams("annotation-line.pdf")
|
buildGetDocumentParams("annotation-line.pdf")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user