diff --git a/src/adapters/browser-transfer/image-cdn/browser-image-probe.ts b/src/adapters/browser-transfer/image-cdn/browser-image-probe.ts index 99fd66e9..62129718 100644 --- a/src/adapters/browser-transfer/image-cdn/browser-image-probe.ts +++ b/src/adapters/browser-transfer/image-cdn/browser-image-probe.ts @@ -49,7 +49,10 @@ export function createBrowserImageProbe( const createBitmap = dependencies.createBitmap ?? (typeof createImageBitmap === "function" - ? async (image: Blob) => createImageBitmap(image) + ? // Q-6.1-8. The header parser reads pre-rotation dimensions, so the + // decode must not apply EXIF/irot orientation and swap them. + async (image: Blob) => + createImageBitmap(image, { imageOrientation: "none" }) : undefined); const timeoutMs = dependencies.timeoutMs ?? DEFAULT_TIMEOUT_MS; const timers = snapshotAbortTimers( diff --git a/tests/unit/image-cdn-browser-probe.test.ts b/tests/unit/image-cdn-browser-probe.test.ts index 183c8de1..d7c09204 100644 --- a/tests/unit/image-cdn-browser-probe.test.ts +++ b/tests/unit/image-cdn-browser-probe.test.ts @@ -108,6 +108,40 @@ describe("browser image probe", () => { expect(close).toHaveBeenCalledTimes(samples.length); }); + // Q-6.1-8. The header parser reads pre-rotation dimensions, so the native + // decode must not apply EXIF/irot orientation either; otherwise an + // orientation 5-8 JPEG decodes with width and height swapped. + it("decodes with the default bitmap factory without applying orientation", async () => { + const bytes = jpegBytes(640, 360); + const exactUrl = imageUrl.replace("format=png", "format=jpeg"); + const nativeCreateImageBitmap = vi.fn(async () => ({ + width: 640, + height: 360, + close() {}, + })); + vi.stubGlobal("createImageBitmap", nativeCreateImageBitmap); + try { + const probe = createBrowserImageProbe({ + fetcher: (async () => + responseAt(exactUrl, bytes, { + status: 200, + headers: publicImageHeaders("image/jpeg", bytes.byteLength), + })) as typeof fetch, + }); + await expect( + probe.probe( + request({ absoluteUrl: exactUrl, expectedMediaType: "image/jpeg" }), + ), + ).resolves.toMatchObject({ ok: true }); + expect(nativeCreateImageBitmap).toHaveBeenCalledWith( + expect.any(Blob), + { imageOrientation: "none" }, + ); + } finally { + vi.unstubAllGlobals(); + } + }); + it("fails closed on duplicate/conflicting cache directives and oversized bodies", async () => { const png = pngBytes(640, 360); const createBitmap = vi.fn(async () => ({