Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue when ZIP64 extra field has different size than expected fro… #308

Open
wants to merge 2 commits into
base: development
Choose a base branch
from
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
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)
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
Loading