Skip to content

Commit 643317e

Browse files
authored
Merge pull request marmelroy#75 from marmelroy/bugfix/issue74
+Fix for issue marmelroy#74
2 parents 915876f + af563e5 commit 643317e

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

Zip.xcodeproj/project.pbxproj

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
303B4F6E1E4CBE5000DC1633 /* permissions.zip in Resources */ = {isa = PBXBuildFile; fileRef = 303B4F6D1E4CBE5000DC1633 /* permissions.zip */; };
11+
305237181E64595700CA46D1 /* unsupported_permissions.zip in Resources */ = {isa = PBXBuildFile; fileRef = 305237171E64595700CA46D1 /* unsupported_permissions.zip */; };
1112
342545901CE525B200336074 /* Zip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347E3AD71C1E04C900A11FD3 /* Zip.swift */; };
1213
342545921CE525B200336074 /* unzip.c in Sources */ = {isa = PBXBuildFile; fileRef = 342FC0EB1C5044DC0023A3C3 /* unzip.c */; };
1314
342545941CE525B200336074 /* QuickZip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3443A3F51C4AB8A3004AD173 /* QuickZip.swift */; };
@@ -71,6 +72,7 @@
7172

7273
/* Begin PBXFileReference section */
7374
303B4F6D1E4CBE5000DC1633 /* permissions.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = permissions.zip; sourceTree = "<group>"; };
75+
305237171E64595700CA46D1 /* unsupported_permissions.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = unsupported_permissions.zip; sourceTree = "<group>"; };
7476
342545B51CE525B200336074 /* Zip.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Zip.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7577
342FC0E71C5044DC0023A3C3 /* crypt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crypt.h; sourceTree = "<group>"; };
7678
342FC0E81C5044DC0023A3C3 /* ioapi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ioapi.c; sourceTree = "<group>"; };
@@ -196,6 +198,7 @@
196198
347E3A821C1DFFB500A11FD3 /* ZipTests */ = {
197199
isa = PBXGroup;
198200
children = (
201+
305237171E64595700CA46D1 /* unsupported_permissions.zip */,
199202
303B4F6D1E4CBE5000DC1633 /* permissions.zip */,
200203
34940A221C58876200D41574 /* 3crBXeO.gif */,
201204
34940A231C58876200D41574 /* kYkLkPf.gif */,
@@ -418,6 +421,7 @@
418421
isa = PBXResourcesBuildPhase;
419422
buildActionMask = 2147483647;
420423
files = (
424+
305237181E64595700CA46D1 /* unsupported_permissions.zip in Resources */,
421425
303B4F6E1E4CBE5000DC1633 /* permissions.zip in Resources */,
422426
34940A251C58876200D41574 /* kYkLkPf.gif in Resources */,
423427
3443A3FD1C4AD199004AD173 /* bb8.zip in Resources */,

Zip/Zip.swift

+10-5
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,16 @@ public class Zip {
199199
}
200200

201201
//Set file permissions from current fileInfo
202-
let permissions = (fileInfo.external_fa >> 16) & 0x1FF
203-
do {
204-
try fileManager.setAttributes([.posixPermissions : permissions], ofItemAtPath: fullPath)
205-
} catch let error {
206-
print("Failed to set permissions to file \(fullPath)")
202+
if fileInfo.external_fa != 0 {
203+
let permissions = (fileInfo.external_fa >> 16) & 0x1FF
204+
//We will devifne a valid permission range between Owner read only to full access
205+
if permissions >= 0o400 && permissions <= 0o777 {
206+
do {
207+
try fileManager.setAttributes([.posixPermissions : permissions], ofItemAtPath: fullPath)
208+
} catch {
209+
print("Failed to set permissions to file \(fullPath), error: \(error)")
210+
}
211+
}
207212
}
208213

209214
ret = unzGoToNextFile(zip)

ZipTests/ZipTests.swift

+18
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,24 @@ class ZipTests: XCTestCase {
217217
}
218218
}
219219

220+
func testUnzipWithUnsupportedPermissions() {
221+
do {
222+
let permissionsURL = Bundle(for: ZipTests.self).url(forResource: "unsupported_permissions", withExtension: "zip")!
223+
let unzipDestination = try Zip.quickUnzipFile(permissionsURL)
224+
print(unzipDestination)
225+
let fileManager = FileManager.default
226+
let permission644 = unzipDestination.appendingPathComponent("unsupported_permission").appendingPathExtension("txt")
227+
do {
228+
let attributes644 = try fileManager.attributesOfItem(atPath: permission644.path)
229+
XCTAssertEqual(attributes644[.posixPermissions] as? Int, 0o644)
230+
} catch {
231+
XCTFail("Failed to get file attributes \(error)")
232+
}
233+
} catch {
234+
XCTFail("Failed extract unsupported_permissions.zip")
235+
}
236+
}
237+
220238
func testUnzipPermissions() {
221239
do {
222240
let permissionsURL = Bundle(for: ZipTests.self).url(forResource: "permissions", withExtension: "zip")!

ZipTests/unsupported_permissions.zip

287 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)