Skip to content

Commit bf087b1

Browse files
committed
fix(runtime): resync image-metadata.mjs after #68
#68 added readRawDimensions() directly to the generated macos/scripts/image-metadata.mjs without updating the canonical runtime/image-metadata.mjs source, so tools/sync-runtime-assets.mjs --check fails on main and windows/scripts/image-metadata.mjs never picked up the new export at all. Port the same split to the source and regenerate both platform outputs.
1 parent 918e8df commit bf087b1

2 files changed

Lines changed: 28 additions & 12 deletions

File tree

runtime/image-metadata.mjs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,21 @@ export function classifyImageDimensions({ width, height }) {
119119
};
120120
}
121121

122-
export function readImageMetadata(value, extension = "") {
122+
// Raw pixel dimensions straight from the container header — no decode, and no
123+
// safety-cap classification, so callers can reject oversized images *before*
124+
// anything rasterizes them. Returns null for formats this header parser does
125+
// not recognize (e.g. HEIC/TIFF).
126+
export function readRawDimensions(value, extension = "") {
123127
const bytes = value instanceof Uint8Array ? value : new Uint8Array(value);
124128
const normalized = extension.toLowerCase();
125-
let dimensions = null;
126-
if (normalized === ".png" || bytes[0] === 0x89) dimensions = pngDimensions(bytes);
127-
else if (normalized === ".jpg" || normalized === ".jpeg" ||
128-
(bytes[0] === 0xff && bytes[1] === 0xd8)) dimensions = jpegDimensions(bytes);
129-
else if (normalized === ".webp" || ascii(bytes, 8, 4) === "WEBP") dimensions = webpDimensions(bytes);
129+
if (normalized === ".png" || bytes[0] === 0x89) return pngDimensions(bytes);
130+
if (normalized === ".jpg" || normalized === ".jpeg" ||
131+
(bytes[0] === 0xff && bytes[1] === 0xd8)) return jpegDimensions(bytes);
132+
if (normalized === ".webp" || ascii(bytes, 8, 4) === "WEBP") return webpDimensions(bytes);
133+
return null;
134+
}
135+
136+
export function readImageMetadata(value, extension = "") {
137+
const dimensions = readRawDimensions(value, extension);
130138
return dimensions ? classifyImageDimensions(dimensions) : null;
131139
}

windows/scripts/image-metadata.mjs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,22 @@ export function classifyImageDimensions({ width, height }) {
123123
};
124124
}
125125

126-
export function readImageMetadata(value, extension = "") {
126+
// Raw pixel dimensions straight from the container header — no decode, and no
127+
// safety-cap classification, so callers can reject oversized images *before*
128+
// anything rasterizes them. Returns null for formats this header parser does
129+
// not recognize (e.g. HEIC/TIFF).
130+
export function readRawDimensions(value, extension = "") {
127131
const bytes = value instanceof Uint8Array ? value : new Uint8Array(value);
128132
const normalized = extension.toLowerCase();
129-
let dimensions = null;
130-
if (normalized === ".png" || bytes[0] === 0x89) dimensions = pngDimensions(bytes);
131-
else if (normalized === ".jpg" || normalized === ".jpeg" ||
132-
(bytes[0] === 0xff && bytes[1] === 0xd8)) dimensions = jpegDimensions(bytes);
133-
else if (normalized === ".webp" || ascii(bytes, 8, 4) === "WEBP") dimensions = webpDimensions(bytes);
133+
if (normalized === ".png" || bytes[0] === 0x89) return pngDimensions(bytes);
134+
if (normalized === ".jpg" || normalized === ".jpeg" ||
135+
(bytes[0] === 0xff && bytes[1] === 0xd8)) return jpegDimensions(bytes);
136+
if (normalized === ".webp" || ascii(bytes, 8, 4) === "WEBP") return webpDimensions(bytes);
137+
return null;
138+
}
139+
140+
export function readImageMetadata(value, extension = "") {
141+
const dimensions = readRawDimensions(value, extension);
134142
return dimensions ? classifyImageDimensions(dimensions) : null;
135143
}
136144

0 commit comments

Comments
 (0)