From 64007e777e6a84cafb02c19b61cf411eb473331f Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Wed, 23 Apr 2025 09:55:04 +0200 Subject: [PATCH] Ensure that the /Form XObject /Resources-entry is actually a dictionary (issue 19848) --- src/core/evaluator.js | 22 +++++++++++++++------- test/pdfs/.gitignore | 1 + test/pdfs/issue19848.pdf | Bin 0 -> 6803 bytes test/test_manifest.json | 14 ++++++++++++++ 4 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 test/pdfs/issue19848.pdf diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 50380aea7..e84bad23e 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -465,7 +465,7 @@ class PartialEvaluator { localColorSpaceCache, seenRefs ) { - const dict = xobj.dict; + const { dict } = xobj; const matrix = lookupMatrix(dict.getArray("Matrix"), null); const bbox = lookupNormalRect(dict.getArray("BBox"), null); @@ -521,10 +521,12 @@ class PartialEvaluator { const args = [f32matrix, f32bbox]; operatorList.addOp(OPS.paintFormXObjectBegin, args); + const localResources = dict.get("Resources"); + await this.getOperatorList({ stream: xobj, task, - resources: dict.get("Resources") || resources, + resources: localResources instanceof Dict ? localResources : resources, operatorList, initialState, prevRefs: seenRefs, @@ -3298,14 +3300,15 @@ class PartialEvaluator { if (!(xobj instanceof BaseStream)) { throw new FormatError("XObject should be a stream"); } + const { dict } = xobj; - const type = xobj.dict.get("Subtype"); + const type = dict.get("Subtype"); if (!(type instanceof Name)) { throw new FormatError("XObject should have a Name subtype"); } if (type.name !== "Form") { - emptyXObjectCache.set(name, xobj.dict.objId, true); + emptyXObjectCache.set(name, dict.objId, true); resolveXObject(); return; @@ -3319,11 +3322,13 @@ class PartialEvaluator { const currentState = stateManager.state.clone(); const xObjStateManager = new StateManager(currentState); - const matrix = lookupMatrix(xobj.dict.getArray("Matrix"), null); + const matrix = lookupMatrix(dict.getArray("Matrix"), null); if (matrix) { xObjStateManager.transform(matrix); } + const localResources = dict.get("Resources"); + // Enqueue the `textContent` chunk before parsing the /Form // XObject. enqueueChunk(); @@ -3348,7 +3353,10 @@ class PartialEvaluator { .getTextContent({ stream: xobj, task, - resources: xobj.dict.get("Resources") || resources, + resources: + localResources instanceof Dict + ? localResources + : resources, stateManager: xObjStateManager, includeMarkedContent, sink: sinkWrapper, @@ -3362,7 +3370,7 @@ class PartialEvaluator { }) .then(function () { if (!sinkWrapper.enqueueInvoked) { - emptyXObjectCache.set(name, xobj.dict.objId, true); + emptyXObjectCache.set(name, dict.objId, true); } resolveXObject(); }, rejectXObject); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 9c4b08a8e..7d5ba5fc3 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -473,6 +473,7 @@ !issue6069.pdf !issue6106.pdf !issue6296.pdf +!issue19848.pdf !bug852992_reduced.pdf !issue13271.pdf !issue6298.pdf diff --git a/test/pdfs/issue19848.pdf b/test/pdfs/issue19848.pdf new file mode 100644 index 0000000000000000000000000000000000000000..45be7ea0e130b2153f27c10a26899b89aac5da1b GIT binary patch literal 6803 zcmeHMPj4eh6>r3@SoI1nb3{U=pwVV_v8$^8x!ZEQ<8hpwXvdR~c$67tawvC~?Vj`> zPyb1r5gfVj1-S45*b7=#+&G{`+?NGD00J&ZNbm`OS6%LQ$IeKb!`@;m?&?>+_v+QF z_g>Yj+&$dgYtW{t-u>I(zxcE2AcErYOSRL%k9aiAW=PjsIzGz1J>wY~^Qj;0Z2kMUzuQ8-x3hI(4#{xd=QID|>x3V_emrtt zpSg~=^o^@$8j*xu%j}(BoSaR9_yW@=5p$H259gIOS2!1Jeg){c6>gp~_8#0_Wb=t)GfM}JB z8gflW>ChWeuG3`c`~|iq$8+10I0;$SW%GI9yG%F+o_muHUUk**FstFPy&Jo^ShfA# zZl3#I+i)Dqv~=OXCTkef9yi9CZZ<5J@RnwJ+@wZfk*mBLa`z)xvB>46+=;^->T=T1 ziEcCuSJxV2MsyH9(QV7qJddzaZjE;-w}XX$)Es^lO*P`uk73H!I~;U?Z|dvb)&Y9^ zFp0g~`a9)SpHW_QY%m|3TX# ziqj=sMBTlPSb>%F&51|~f-ffFB2Qf6A zIMgYQn(qYO3PV0zDY^k@`xd2)>35r%=&#qDCq~AE^&Us#Jq&Xfy%RRMn8xGyypB)a}v3 z{bO_wjb5rcX^xu4HoRF6JrA|M6>$~1t);r1{ zfBC&^Q$Jd}2YIu8lwQ$qdjxak%4gSzTg|o?MRArQT6h**qj)}(;Q$cRF`Jr=Yy(!v zIfbZ7M8zY+s_x@UM+GDiDk(33H44jA`x%h1h^kGF-hS{&be%(2w#I z&v}x~;yh)MC)EJ)V_22yrC==-gdWLRyshXpVli03o+ZrVAxqBi#0S0bqcjj29t`lY zG}SZD2P=v>{74eOU;$54U&VpM#vG@z>viz}4gGYA zkZp_3S2;^Weuw6a1rs^Kk_c(Y(QvQu4BV5W^=jVMD|`v}s;T!159`Tmk4YOZi2H6Zhmg5~r_<@8U)Zhn8K*bg2LFUhcOMD<#_labEB3Yl* zSf5lp&t&Il7AFyg2!QMWPMBgQd712HHD0*KgP4MQ&(gVAVFv~QTABeC6~YU1$;@la zuue;t^d-iZ7{7+`D-6$ODvsoMvBbv`AJ_2l5>T;u{<#kt#?lJ8WXvUFUSrHFj!W4I zVG35bEXk)b0hY;el?25mv`kgi-jd>veNSvGBJrKVPLsoKCAP%nd2x|&aqQ8kN~#aC zOj9?}1TATXVS;G!K~YK5Ee&$+Rhk7MuudxwYx2G-&9EIf)L$LrdR}qzxr#H00ejk2 znr_(}IvdU=t>9YI*&rrt%~$0amN+4-(QL9YMuAw9r|aV6xW=ouHfd0itZYyXMzx%vHHQgFeI@mS)J<{si)a+@b*R#o9%OC^o yLAPU>gt?sRcFU!dc|>z8&1)I0@x;|w%d@-U2m&|MNmlrY1y|ha-MfQ>J@x;oO0R+d literal 0 HcmV?d00001 diff --git a/test/test_manifest.json b/test/test_manifest.json index 002bf23ab..2ffe7549f 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -3886,6 +3886,20 @@ "rounds": 1, "type": "eq" }, + { + "id": "issue19848-eq", + "file": "pdfs/issue19848.pdf", + "md5": "a6b05b61c883542e647b9a5a628e6422", + "rounds": 1, + "type": "eq" + }, + { + "id": "issue19848-text", + "file": "pdfs/issue19848.pdf", + "md5": "a6b05b61c883542e647b9a5a628e6422", + "rounds": 1, + "type": "text" + }, { "id": "issue14824", "file": "pdfs/issue14824.pdf",