From a5f7263bfb174df9587291e808ce547f2249e95b Mon Sep 17 00:00:00 2001 From: Rick M Date: Mon, 29 Apr 2024 22:41:52 -0700 Subject: [PATCH] Remove constraint that zip64 field values be greater than 0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In ZIP64 archives, certain standard field values (like file sizes and offsets within the archive) are set to 0xFFFFFFFF, and actual values are provided in the ZIP64 extra fields. The code was requiring these values be > 0. If a value was 0, the non-ZIP64 value was returned (0xFFFFFFFF), and thus almost guaranteed to be incorrect. This patch removes that test for `compressedSize`, `uncompressedSize`, and `relativeOffsetOfLocalHeader`. While it’s unlikely for a file to have zero length, it’s not impossible, and it’s very likely for a local header to be at offset 0. --- Sources/ZIPFoundation/Entry.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/ZIPFoundation/Entry.swift b/Sources/ZIPFoundation/Entry.swift index 300ab802..69a9cbbe 100644 --- a/Sources/ZIPFoundation/Entry.swift +++ b/Sources/ZIPFoundation/Entry.swift @@ -299,19 +299,19 @@ extension Entry.CentralDirectoryStructure { extension Entry.CentralDirectoryStructure { var effectiveCompressedSize: UInt64 { - if self.isZIP64, let compressedSize = self.zip64ExtendedInformation?.compressedSize, compressedSize > 0 { + if self.isZIP64, 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, 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, let offset = self.zip64ExtendedInformation?.relativeOffsetOfLocalHeader { return offset } return UInt64(relativeOffsetOfLocalHeader)