diff --git a/Sources/ZIPFoundation/Entry+ZIP64.swift b/Sources/ZIPFoundation/Entry+ZIP64.swift index dec18688..c8188756 100644 --- a/Sources/ZIPFoundation/Entry+ZIP64.swift +++ b/Sources/ZIPFoundation/Entry+ZIP64.swift @@ -104,7 +104,10 @@ extension Entry.ZIP64ExtendedInformation { init?(data: Data, fields: [Field]) { let headerLength = 4 - guard fields.reduce(0, { $0 + $1.size }) + headerLength == data.count else { return nil } + let tmpDataSize:UInt16 = data.scanValue(start: 2) + guard Int(tmpDataSize) + headerLength == data.count else { + return nil + } var readOffset = headerLength func value(of field: Field) throws -> T where T: BinaryInteger { if fields.contains(field) { @@ -120,7 +123,7 @@ extension Entry.ZIP64ExtendedInformation { } } do { - dataSize = data.scanValue(start: 2) + dataSize = tmpDataSize uncompressedSize = try value(of: .uncompressedSize) compressedSize = try value(of: .compressedSize) relativeOffsetOfLocalHeader = try value(of: .relativeOffsetOfLocalHeader) diff --git a/Tests/ZIPFoundationTests/ZIPFoundationEntryTests+ZIP64.swift b/Tests/ZIPFoundationTests/ZIPFoundationEntryTests+ZIP64.swift index ea0e7a52..71abc26d 100644 --- a/Tests/ZIPFoundationTests/ZIPFoundationEntryTests+ZIP64.swift +++ b/Tests/ZIPFoundationTests/ZIPFoundationEntryTests+ZIP64.swift @@ -132,7 +132,7 @@ extension ZIPFoundationTests { let invalidExtraField2 = ZIP64ExtendedInformation(data: Data(extraFieldBytesMissingByte), fields: [.compressedSize, .uncompressedSize]) XCTAssertNil(invalidExtraField2) - let extraFieldBytesWithWrongFields: [UInt8] = [0x01, 0x00, 0x10, 0x00, 0x0a, 0x00, 0x00, 0x00, + let extraFieldBytesWithWrongFields: [UInt8] = [0x01, 0x00, 0x0a, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] let invalidExtraField3 = ZIP64ExtendedInformation(data: Data(extraFieldBytesWithWrongFields),