From 9e387b7ec35fecf3909a248a0b251e75fa5d70d6 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 24 Sep 2026 13:11:43 +0900 Subject: [PATCH] fix(browser-transfer): decode probe images without applying orientation (Q-6.1-8) The header parser reads pre-rotation dimensions, but the default createImageBitmap call applied EXIF/irot orientation, so an orientation 5-8 JPEG or a rotated AVIF decoded with width and height swapped and was rejected. The default bitmap factory now passes { imageOrientation: "none" }. An injected createBitmap is unchanged. Verified: RED test "decodes with the default bitmap factory without applying orientation" (options were missing) + all gates. Real-browser decode of a rotated image is not exercised here. Co-Authored-By: Claude Opus 5.5 --- .../image-cdn/browser-image-probe.ts | 5 ++- tests/unit/image-cdn-browser-probe.test.ts | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) 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 () => ({