Skip to content

Commit 124092f

Browse files
committed
Check header CRC
1 parent d29cc1e commit 124092f

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/isal/igzip.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,12 @@ def _gzip_header_end(data: bytes) -> int:
279279
pos = fcomment_end
280280
if flags & FHCRC:
281281
pos += 2
282+
header_crc = int.from_bytes(data[pos: pos + 2], "little", signed=False)
283+
# CRC is stored as a 16-bit integer by taking last bits of crc32.
284+
crc = isal_zlib.crc32(data[:pos]) & 0xFFFF
285+
if header_crc != crc:
286+
raise BadGzipFile(f"Corrupted header. Checksums do not "
287+
f"match: {crc} != {header_crc}")
282288
return pos
283289

284290

0 commit comments

Comments
 (0)