fix: validate media size dimensions

This commit is contained in:
Peter Steinberger
2026-05-28 16:30:19 -04:00
parent 205d6b730f
commit 6966c202b9
2 changed files with 13 additions and 0 deletions

View File

@@ -241,6 +241,16 @@ describe("media-generation runtime shared normalization", () => {
expect(deriveAspectRatioFromSize("1024x1536")).toBe("2:3");
});
it("rejects unsafe size dimensions before deriving ratios", () => {
expect(deriveAspectRatioFromSize("9007199254740993x3")).toBeUndefined();
expect(
resolveClosestSize({
requestedSize: "9007199254740993x3",
supportedSizes: ["1024x1024", "1536x1024"],
}),
).toBeUndefined();
});
it("maps unsupported sizes to the closest supported size", () => {
expect(
resolveClosestSize({

View File

@@ -311,6 +311,9 @@ function parseSizeValue(raw?: string | null): ParsedSize | null {
if (!pair) {
return null;
}
if (!Number.isSafeInteger(pair.width) || !Number.isSafeInteger(pair.height)) {
return null;
}
return {
width: pair.width,
height: pair.height,