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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
818cbd3839
commit
9e387b7ec3
@@ -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(
|
||||
|
||||
@@ -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 () => ({
|
||||
|
||||
Reference in New Issue
Block a user