Skip to content

Commit

Permalink
Remove constraint that zip64 field values be greater than 0
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JetForMe committed Apr 30, 2024
1 parent 02b6abe commit a5f7263
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Sources/ZIPFoundation/Entry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a5f7263

Please sign in to comment.