fix(screenshot): reject invalid PNG header dimensions (#2472)

This commit is contained in:
Rudy Mizrahi Celekli
2026-10-13 15:50:44 +09:00
committed by GitHub
parent 68ecf3df8c
commit e74e4e951b
4 changed files with 90 additions and 1 deletions
+7 -1
View File
@@ -8,10 +8,16 @@ export const readPngHeaderDimensions = (
if (
bytes.byteLength < 24 ||
!bytes.subarray(0, 8).equals(PNG_SIGNATURE) ||
bytes.readUInt32BE(8) !== 13 ||
!bytes.subarray(12, 16).equals(IHDR_TYPE)
)
return undefined;
const width = bytes.readUInt32BE(16);
const height = bytes.readUInt32BE(20);
return width === 0 || height === 0 ? undefined : { width, height };
return width === 0 ||
height === 0 ||
width > 0x7fff_ffff ||
height > 0x7fff_ffff
? undefined
: { width, height };
};