Fix IHDR chunk extraction to return only the chunk itself

This commit is contained in:
aradhyacp
2026-01-10 01:23:31 +05:30
parent 624760c6ba
commit 05782b710a
+3 -2
View File
@@ -57,8 +57,9 @@ class PNG:
pos = data.find(b"IHDR")
if pos == -1:
return -1, b""
idat_begin = data.find(b"IDAT")
return pos, data[pos - 4 : idat_begin - 4 if idat_begin != -1 else pos + 21]
# IHDR chunk is always 25 bytes: 4 (length) + 4 (type) + 13 (data) + 4 (CRC)
# Only return the IHDR chunk itself, not everything up to IDAT
return pos, data[pos - 4 : pos + 21]
def check_header(self) -> bool:
"""Check and fix PNG header."""