Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Sources/ZIPFoundation/Archive+ZIP64.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ extension Archive.ZIP64EndOfCentralDirectoryRecord {
self.sizeOfZIP64EndOfCentralDirectoryRecord = data.scanValue(start: 4)
self.versionMadeBy = data.scanValue(start: 12)
self.versionNeededToExtract = data.scanValue(start: 14)
// Version Needed to Extract: 4.5 - File uses ZIP64 format extensions
guard self.versionNeededToExtract >= Archive.Version.v45.rawValue else { return nil }
// Note: The ZIP spec recommends versionNeededToExtract >= 4.5 for ZIP64,
// but some producers (e.g. Microsoft Outlook OLM export) write valid ZIP64
// structures with a lower version. We accept the record if the signature matches.
self.numberOfDisk = data.scanValue(start: 16)
self.numberOfDiskStart = data.scanValue(start: 20)
self.totalNumberOfEntriesOnDisk = data.scanValue(start: 24)
Expand Down
9 changes: 6 additions & 3 deletions Sources/ZIPFoundation/Entry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,19 +297,22 @@ extension Entry.CentralDirectoryStructure {
extension Entry.CentralDirectoryStructure {

var effectiveCompressedSize: UInt64 {
if self.isZIP64, let compressedSize = self.zip64ExtendedInformation?.compressedSize, compressedSize > 0 {
if self.isZIP64, self.compressedSize == .max,
let compressedSize = self.zip64ExtendedInformation?.compressedSize {
return compressedSize
}
return UInt64(compressedSize)
}
var effectiveUncompressedSize: UInt64 {
if self.isZIP64, let uncompressedSize = self.zip64ExtendedInformation?.uncompressedSize, uncompressedSize > 0 {
if self.isZIP64, self.uncompressedSize == .max,
let uncompressedSize = self.zip64ExtendedInformation?.uncompressedSize {
return uncompressedSize
}
return UInt64(uncompressedSize)
}
var effectiveRelativeOffsetOfLocalHeader: UInt64 {
if self.isZIP64, let offset = self.zip64ExtendedInformation?.relativeOffsetOfLocalHeader, offset > 0 {
if self.isZIP64, self.relativeOffsetOfLocalHeader == .max,
let offset = self.zip64ExtendedInformation?.relativeOffsetOfLocalHeader {
return offset
}
return UInt64(relativeOffsetOfLocalHeader)
Expand Down
24 changes: 13 additions & 11 deletions Tests/ZIPFoundationTests/ZIPFoundationArchiveTests+ZIP64.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,19 @@ extension ZIPFoundationTests {
additionalDataProvider: {_ -> Data in
return Data() })
XCTAssertNil(invalidEOCDRecord2)
let eocdRecordWithWrongVersion: [UInt8] = [0x50, 0x4b, 0x06, 0x06, 0x2c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1e, 0x03, 0x14, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
let invalidEOCDRecord3 = Archive.ZIP64EndOfCentralDirectoryRecord(data: Data(eocdRecordWithWrongVersion),
additionalDataProvider: {_ -> Data in
return Data() })
XCTAssertNil(invalidEOCDRecord3)
// Some ZIP producers (e.g. Microsoft Outlook OLM export) write valid ZIP64
// structures with versionNeededToExtract < 4.5. These should be accepted.
let eocdRecordWithLowVersion: [UInt8] = [0x50, 0x4b, 0x06, 0x06, 0x2c, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1e, 0x03, 0x14, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x4c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x5a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
let lowVersionEOCDRecord = Archive.ZIP64EndOfCentralDirectoryRecord(data: Data(eocdRecordWithLowVersion),
additionalDataProvider: {_ -> Data in
return Data() })
XCTAssertNotNil(lowVersionEOCDRecord)
}

func testArchiveZIP64EOCDLocator() {
Expand Down