Skip to content

Commit 7ea7a94

Browse files
Merge pull request #20160 from calixteman/issue20155
Check the setDash arguments
2 parents 32ea986 + 1d4ae78 commit 7ea7a94

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/core/evaluator.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,6 +2206,22 @@ class PartialEvaluator {
22062206
args[0] = Math.abs(thickness);
22072207
break;
22082208
}
2209+
case OPS.setDash: {
2210+
const dashPhase = args[1];
2211+
if (typeof dashPhase !== "number") {
2212+
warn(`Invalid setDash: ${dashPhase}`);
2213+
continue;
2214+
}
2215+
const dashArray = args[0];
2216+
if (!Array.isArray(dashArray)) {
2217+
warn(`Invalid setDash: ${dashArray}`);
2218+
continue;
2219+
}
2220+
if (dashArray.some(x => typeof x !== "number")) {
2221+
args[0] = dashArray.filter(x => typeof x === "number");
2222+
}
2223+
break;
2224+
}
22092225
case OPS.moveTo:
22102226
case OPS.lineTo:
22112227
case OPS.curveTo:

test/unit/evaluator_spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,18 @@ describe("evaluator", function () {
357357
expect(result.argsArray).toEqual([]);
358358
expect(result.fnArray).toEqual([]);
359359
});
360+
361+
it("should handle invalid dash stuff", async function () {
362+
const stream = new StringStream("[ none ] 0 d");
363+
const result = await runOperatorListCheck(
364+
partialEvaluator,
365+
stream,
366+
new ResourcesMock()
367+
);
368+
expect(result.argsArray[0][0]).toEqual([]);
369+
expect(result.argsArray[0][1]).toEqual(0);
370+
expect(result.fnArray[0]).toEqual(OPS.setDash);
371+
});
360372
});
361373

362374
describe("thread control", function () {

0 commit comments

Comments
 (0)