Fix problem with repeated access to zip entry's data

This commit is contained in:
Timofey Solomko
2017-07-15 22:08:33 +03:00
parent 32394d66c0
commit 0b611edbea
3 changed files with 7 additions and 0 deletions
+2
View File
@@ -85,6 +85,8 @@ public class ZipEntry: ContainerEntry {
localHeader!.lastModFileTime == cdEntry.lastModFileTime &&
localHeader!.lastModFileDate == cdEntry.lastModFileDate
else { throw ZipError.wrongLocalHeader }
} else {
pointerData.index += localHeader!.headerSize
}
let hasDataDescriptor = localHeader!.generalPurposeBitFlags & 0x08 != 0
+3
View File
@@ -25,6 +25,8 @@ struct ZipLocalHeader {
private(set) var accessTimestamp: UInt32?
private(set) var creationTimestamp: UInt32?
let headerSize: Int
init(_ pointerData: DataWithPointer) throws {
// Check signature.
guard pointerData.uint32() == 0x04034b50
@@ -47,6 +49,7 @@ struct ZipLocalHeader {
let fileNameLength = pointerData.uint16().toInt()
let extraFieldLength = pointerData.uint16().toInt()
self.headerSize = 30 + fileNameLength + extraFieldLength
guard let fileName = ZipCommon.getStringField(pointerData, fileNameLength, useUtf8)
else { throw ZipError.wrongTextField }
+2
View File
@@ -151,6 +151,8 @@ class ZipTests: XCTestCase {
}
XCTAssertEqual(try? entries[0].data(), answerData)
// Test repeat of getting entry data (there was a problem with it).
XCTAssertEqual(try? entries[0].data(), answerData)
}
func testZipBZip2() {