fix(pdf): PNG gate inflates IDAT natively against the exact raw size, validates IHDR fields, refuses zero dimensions and interlace (UPNG inflateRaw spin)

This commit is contained in:
bchanot committed 2026-10-11 14:52:03 +02:00
1 parent 0ceb357b18
commit cb95627a11
4 files changed
+412 -76

No files matched your search

+7 -2
View File
@@ -14,9 +14,14 @@ function concat(chunks: Uint8Array[], total: number): Uint8Array {
return out
}
/** FlateDecode under the cap. Null on failure or when the cap is exceeded. */
/**
* FlateDecode (zlib framing) under `limit`, the attachment cap by default.
* Null on any failure (truncated or corrupt stream, trailing junk, bad
* checksum) or as soon as the output exceeds the limit.
*/
export async function inflateFlate(
bytes: Uint8Array,
limit: number = MAX_ATTACHMENT_BYTES,
): Promise<Uint8Array | null> {
if (typeof DecompressionStream === 'undefined') return null
try {
@@ -31,7 +36,7 @@ export async function inflateFlate(
const { done, value } = await reader.read()
if (done) break
total += value.byteLength
if (total > MAX_ATTACHMENT_BYTES) {
if (total > limit) {
await reader.cancel()
return null
}