Check the setDash arguments

It fixes #20155.
This commit is contained in:
Calixte Denizet 2025-08-09 22:34:40 +02:00
parent 41ca92b2ea
commit 1d4ae786f4
2 changed files with 28 additions and 0 deletions

View File

@ -2206,6 +2206,22 @@ class PartialEvaluator {
args[0] = Math.abs(thickness);
break;
}
case OPS.setDash: {
const dashPhase = args[1];
if (typeof dashPhase !== "number") {
warn(`Invalid setDash: ${dashPhase}`);
continue;
}
const dashArray = args[0];
if (!Array.isArray(dashArray)) {
warn(`Invalid setDash: ${dashArray}`);
continue;
}
if (dashArray.some(x => typeof x !== "number")) {
args[0] = dashArray.filter(x => typeof x === "number");
}
break;
}
case OPS.moveTo:
case OPS.lineTo:
case OPS.curveTo:

View File

@ -357,6 +357,18 @@ describe("evaluator", function () {
expect(result.argsArray).toEqual([]);
expect(result.fnArray).toEqual([]);
});
it("should handle invalid dash stuff", async function () {
const stream = new StringStream("[ none ] 0 d");
const result = await runOperatorListCheck(
partialEvaluator,
stream,
new ResourcesMock()
);
expect(result.argsArray[0][0]).toEqual([]);
expect(result.argsArray[0][1]).toEqual(0);
expect(result.fnArray[0]).toEqual(OPS.setDash);
});
});
describe("thread control", function () {