Reject ambiguous PNG headers before pixel validation

This commit is contained in:
Artyom
2026-11-06 21:33:09 +03:00
parent bcbd4ebc02
commit 7c8a1a6489
21 changed files with 498 additions and 34 deletions
+5
View File
@@ -34,6 +34,11 @@ def png_from_idat(
BROKEN_PNG = png_from_idat(b"not a zlib stream")
DUPLICATE_IHDR_PNG = (
SIGNATURE
+ chunk(b"IHDR", struct.pack(">IIBBBBB", 1, 1, 8, 2, 0, 0, 0))
+ png_from_idat(zlib.compress(bytes(4)), 2, 2)[len(SIGNATURE) :]
)
def png(width: int, height: int, *, size: int | None = None, rows: bool = True) -> bytes: