fix: add exotic format decoding to image-to-pdf tool

The image-to-pdf route used ensureSharpCompat (HEIC-only) instead of the
full format decode pipeline from tool-factory. Formats like FITS, PSD,
RAW, EXR, HDR, TGA, etc. passed through undecoded and crashed Sharp.

Replace with validateImageBuffer + decodeToSharpCompat to match the
standard tool pipeline.
This commit is contained in:
SnapOtter
2026-05-11 22:47:10 +08:00
parent 095e3d9488
commit 56e8cf7352
2 changed files with 21 additions and 6 deletions
+3 -3
View File
@@ -216,7 +216,7 @@ describe("image-to-pdf", () => {
// ── Branch coverage: lines 143-147 (processing failure) ───────────
it("returns 422 when processing fails on corrupted image data", async () => {
it("returns 400 when image format is unrecognized", async () => {
const corruptedBuffer = Buffer.alloc(100, 0xff);
const { body, contentType } = createMultipartPayload([
{ name: "file", filename: "bad.png", contentType: "image/png", content: corruptedBuffer },
@@ -230,9 +230,9 @@ describe("image-to-pdf", () => {
body,
});
expect(res.statusCode).toBe(422);
expect(res.statusCode).toBe(400);
const json = JSON.parse(res.body);
expect(json.error).toContain("PDF creation failed");
expect(json.error).toContain("Invalid image");
});
// ── HEIC input handling ───────────────────────────────────────────