From 74ae7c2edc8389207ea58dcca8a86eaa91675584 Mon Sep 17 00:00:00 2001 From: Timofey Solomko Date: Tue, 17 May 2022 13:33:04 +0300 Subject: [PATCH] [GZip] Adjust detection of truncated inputs --- Sources/GZip/GzipArchive.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/GZip/GzipArchive.swift b/Sources/GZip/GzipArchive.swift index 7a840402..0cafe099 100644 --- a/Sources/GZip/GzipArchive.swift +++ b/Sources/GZip/GzipArchive.swift @@ -77,8 +77,9 @@ public class GzipArchive: Archive { } private static func processMember(_ bitReader: LsbBitReader) throws -> Member { - // Valid GZip archive must contain at least 18 bytes of data (10 for header and 8 for checksums). - guard bitReader.bitsLeft >= 18 * 8 + // Valid GZip archive must contain at least 20 bytes of data (10 for the header, 2 for an empty Deflate block, + // and 8 for checksums). + guard bitReader.bitsLeft >= 20 * 8 else { throw GzipError.wrongMagic } let header = try GzipHeader(bitReader)