Skip to content

Commit 64007e7

Browse files
committed
Ensure that the /Form XObject /Resources-entry is actually a dictionary (issue 19848)
1 parent 63e6566 commit 64007e7

4 files changed

Lines changed: 30 additions & 7 deletions

File tree

src/core/evaluator.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ class PartialEvaluator {
465465
localColorSpaceCache,
466466
seenRefs
467467
) {
468-
const dict = xobj.dict;
468+
const { dict } = xobj;
469469
const matrix = lookupMatrix(dict.getArray("Matrix"), null);
470470
const bbox = lookupNormalRect(dict.getArray("BBox"), null);
471471

@@ -521,10 +521,12 @@ class PartialEvaluator {
521521
const args = [f32matrix, f32bbox];
522522
operatorList.addOp(OPS.paintFormXObjectBegin, args);
523523

524+
const localResources = dict.get("Resources");
525+
524526
await this.getOperatorList({
525527
stream: xobj,
526528
task,
527-
resources: dict.get("Resources") || resources,
529+
resources: localResources instanceof Dict ? localResources : resources,
528530
operatorList,
529531
initialState,
530532
prevRefs: seenRefs,
@@ -3298,14 +3300,15 @@ class PartialEvaluator {
32983300
if (!(xobj instanceof BaseStream)) {
32993301
throw new FormatError("XObject should be a stream");
33003302
}
3303+
const { dict } = xobj;
33013304

3302-
const type = xobj.dict.get("Subtype");
3305+
const type = dict.get("Subtype");
33033306
if (!(type instanceof Name)) {
33043307
throw new FormatError("XObject should have a Name subtype");
33053308
}
33063309

33073310
if (type.name !== "Form") {
3308-
emptyXObjectCache.set(name, xobj.dict.objId, true);
3311+
emptyXObjectCache.set(name, dict.objId, true);
33093312

33103313
resolveXObject();
33113314
return;
@@ -3319,11 +3322,13 @@ class PartialEvaluator {
33193322
const currentState = stateManager.state.clone();
33203323
const xObjStateManager = new StateManager(currentState);
33213324

3322-
const matrix = lookupMatrix(xobj.dict.getArray("Matrix"), null);
3325+
const matrix = lookupMatrix(dict.getArray("Matrix"), null);
33233326
if (matrix) {
33243327
xObjStateManager.transform(matrix);
33253328
}
33263329

3330+
const localResources = dict.get("Resources");
3331+
33273332
// Enqueue the `textContent` chunk before parsing the /Form
33283333
// XObject.
33293334
enqueueChunk();
@@ -3348,7 +3353,10 @@ class PartialEvaluator {
33483353
.getTextContent({
33493354
stream: xobj,
33503355
task,
3351-
resources: xobj.dict.get("Resources") || resources,
3356+
resources:
3357+
localResources instanceof Dict
3358+
? localResources
3359+
: resources,
33523360
stateManager: xObjStateManager,
33533361
includeMarkedContent,
33543362
sink: sinkWrapper,
@@ -3362,7 +3370,7 @@ class PartialEvaluator {
33623370
})
33633371
.then(function () {
33643372
if (!sinkWrapper.enqueueInvoked) {
3365-
emptyXObjectCache.set(name, xobj.dict.objId, true);
3373+
emptyXObjectCache.set(name, dict.objId, true);
33663374
}
33673375
resolveXObject();
33683376
}, rejectXObject);

test/pdfs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@
473473
!issue6069.pdf
474474
!issue6106.pdf
475475
!issue6296.pdf
476+
!issue19848.pdf
476477
!bug852992_reduced.pdf
477478
!issue13271.pdf
478479
!issue6298.pdf

test/pdfs/issue19848.pdf

6.64 KB
Binary file not shown.

test/test_manifest.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3886,6 +3886,20 @@
38863886
"rounds": 1,
38873887
"type": "eq"
38883888
},
3889+
{
3890+
"id": "issue19848-eq",
3891+
"file": "pdfs/issue19848.pdf",
3892+
"md5": "a6b05b61c883542e647b9a5a628e6422",
3893+
"rounds": 1,
3894+
"type": "eq"
3895+
},
3896+
{
3897+
"id": "issue19848-text",
3898+
"file": "pdfs/issue19848.pdf",
3899+
"md5": "a6b05b61c883542e647b9a5a628e6422",
3900+
"rounds": 1,
3901+
"type": "text"
3902+
},
38893903
{
38903904
"id": "issue14824",
38913905
"file": "pdfs/issue14824.pdf",

0 commit comments

Comments
 (0)