diff --git a/Zip.xcodeproj/project.pbxproj b/Zip.xcodeproj/project.pbxproj index 6dfd208f0f12933a4766a6f3be73de9654aac100..1b1531918117a7e6622334edc6e8ce1100a5e4b8 100644 --- a/Zip.xcodeproj/project.pbxproj +++ b/Zip.xcodeproj/project.pbxproj @@ -8,6 +8,7 @@ /* Begin PBXBuildFile section */ 303B4F6E1E4CBE5000DC1633 /* permissions.zip in Resources */ = {isa = PBXBuildFile; fileRef = 303B4F6D1E4CBE5000DC1633 /* permissions.zip */; }; + 305237181E64595700CA46D1 /* unsupported_permissions.zip in Resources */ = {isa = PBXBuildFile; fileRef = 305237171E64595700CA46D1 /* unsupported_permissions.zip */; }; 342545901CE525B200336074 /* Zip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 347E3AD71C1E04C900A11FD3 /* Zip.swift */; }; 342545921CE525B200336074 /* unzip.c in Sources */ = {isa = PBXBuildFile; fileRef = 342FC0EB1C5044DC0023A3C3 /* unzip.c */; }; 342545941CE525B200336074 /* QuickZip.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3443A3F51C4AB8A3004AD173 /* QuickZip.swift */; }; @@ -71,6 +72,7 @@ /* Begin PBXFileReference section */ 303B4F6D1E4CBE5000DC1633 /* permissions.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = permissions.zip; sourceTree = ""; }; + 305237171E64595700CA46D1 /* unsupported_permissions.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = unsupported_permissions.zip; sourceTree = ""; }; 342545B51CE525B200336074 /* Zip.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Zip.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 342FC0E71C5044DC0023A3C3 /* crypt.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = crypt.h; sourceTree = ""; }; 342FC0E81C5044DC0023A3C3 /* ioapi.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = ioapi.c; sourceTree = ""; }; @@ -196,6 +198,7 @@ 347E3A821C1DFFB500A11FD3 /* ZipTests */ = { isa = PBXGroup; children = ( + 305237171E64595700CA46D1 /* unsupported_permissions.zip */, 303B4F6D1E4CBE5000DC1633 /* permissions.zip */, 34940A221C58876200D41574 /* 3crBXeO.gif */, 34940A231C58876200D41574 /* kYkLkPf.gif */, @@ -418,6 +421,7 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 305237181E64595700CA46D1 /* unsupported_permissions.zip in Resources */, 303B4F6E1E4CBE5000DC1633 /* permissions.zip in Resources */, 34940A251C58876200D41574 /* kYkLkPf.gif in Resources */, 3443A3FD1C4AD199004AD173 /* bb8.zip in Resources */, diff --git a/Zip/Zip.swift b/Zip/Zip.swift index c806b0d40c6a7e13f60b811aef5bb49b49cda644..80722dc709545cd9bd3fb1e45c2c189cc1261874 100644 --- a/Zip/Zip.swift +++ b/Zip/Zip.swift @@ -199,11 +199,16 @@ public class Zip { } //Set file permissions from current fileInfo - let permissions = (fileInfo.external_fa >> 16) & 0x1FF - do { - try fileManager.setAttributes([.posixPermissions : permissions], ofItemAtPath: fullPath) - } catch let error { - print("Failed to set permissions to file \(fullPath)") + if fileInfo.external_fa != 0 { + let permissions = (fileInfo.external_fa >> 16) & 0x1FF + //We will devifne a valid permission range between Owner read only to full access + if permissions >= 0o400 && permissions <= 0o777 { + do { + try fileManager.setAttributes([.posixPermissions : permissions], ofItemAtPath: fullPath) + } catch { + print("Failed to set permissions to file \(fullPath), error: \(error)") + } + } } ret = unzGoToNextFile(zip) diff --git a/ZipTests/ZipTests.swift b/ZipTests/ZipTests.swift index e26fe8c23aa8a64d665cd5b536f7686d7442da21..282a3e3699517c46d0415a842bddd4ddb9d0c442 100644 --- a/ZipTests/ZipTests.swift +++ b/ZipTests/ZipTests.swift @@ -217,6 +217,24 @@ class ZipTests: XCTestCase { } } + func testUnzipWithUnsupportedPermissions() { + do { + let permissionsURL = Bundle(for: ZipTests.self).url(forResource: "unsupported_permissions", withExtension: "zip")! + let unzipDestination = try Zip.quickUnzipFile(permissionsURL) + print(unzipDestination) + let fileManager = FileManager.default + let permission644 = unzipDestination.appendingPathComponent("unsupported_permission").appendingPathExtension("txt") + do { + let attributes644 = try fileManager.attributesOfItem(atPath: permission644.path) + XCTAssertEqual(attributes644[.posixPermissions] as? Int, 0o644) + } catch { + XCTFail("Failed to get file attributes \(error)") + } + } catch { + XCTFail("Failed extract unsupported_permissions.zip") + } + } + func testUnzipPermissions() { do { let permissionsURL = Bundle(for: ZipTests.self).url(forResource: "permissions", withExtension: "zip")! diff --git a/ZipTests/unsupported_permissions.zip b/ZipTests/unsupported_permissions.zip new file mode 100644 index 0000000000000000000000000000000000000000..5d3dbda8c22b0b3452eba9a946cd332ee44266b1 Binary files /dev/null and b/ZipTests/unsupported_permissions.zip differ