Skip to content

Commit

Permalink
Fix issue when ZIP64 extra field has different size than expected fro…
Browse files Browse the repository at this point in the history
…m Central directory file header
  • Loading branch information
robertlechowicz committed Jan 23, 2024
1 parent cbd9900 commit fa7be46
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions Sources/ZIPFoundation/Entry+ZIP64.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check failure on line 107 in Sources/ZIPFoundation/Entry+ZIP64.swift

View workflow job for this annotation

GitHub Actions / SwiftLint

Colon Spacing Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals (colon)
guard Int(tmpDataSize) + headerLength == data.count else {
return nil
}
var readOffset = headerLength
func value<T>(of field: Field) throws -> T where T: BinaryInteger {
if fields.contains(field) {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit fa7be46

Please sign in to comment.