diff --git a/Tests/GzipTests.swift b/Tests/GzipTests.swift index d2a0967c..d11d4fd6 100644 --- a/Tests/GzipTests.swift +++ b/Tests/GzipTests.swift @@ -246,6 +246,36 @@ class GzipTests: XCTestCase { } } + func testGzipTruncation() throws { + // In this test we check the handling of truncation inside the optional elements (name, comment, "extra field", + // crc) of a GZip header, as well as in the "checksum" information of the archive (last 8 bytes). The sample + // file used is "test4_extra_field" since it contains a header which utilizes all format features. + let testData = try Constants.data(forTest: "test4_extra_field", withType: GzipTests.testType) + + // We test all possible truncation points since there are very few of them. + // The header takes first 79 bytes. + for truncationIndex in 1..<79 { + var thrownError: Error? = nil + XCTAssertThrowsError(try GzipArchive.unarchive(archive: testData[..