diff --git a/Sources/Zip/Zip.swift b/Sources/Zip/Zip.swift index 302285be..cbd76488 100644 --- a/Sources/Zip/Zip.swift +++ b/Sources/Zip/Zip.swift @@ -72,6 +72,7 @@ public class Zip { let zip = unzOpen64(path) defer { unzClose(zip) } if unzGoToFirstFile(zip) != UNZ_OK { + print("XXXXXXXXXXX - 1") throw ZipError.unzipFail } repeat { @@ -81,12 +82,14 @@ public class Zip { ret = unzOpenCurrentFile(zip) } if ret != UNZ_OK { + print("XXXXXXXXXXX - 2") throw ZipError.unzipFail } var fileInfo = unz_file_info64() ret = unzGetCurrentFileInfo64(zip, &fileInfo, nil, 0, nil, 0, nil, 0) if ret != UNZ_OK { unzCloseCurrentFile(zip) + print("XXXXXXXXXXX - 3") throw ZipError.unzipFail } currentPosition += Double(fileInfo.compressed_size) @@ -99,12 +102,8 @@ public class Zip { var pathString = String(cString: fileName) - #if os(Windows) - // Colons are not allowed in Windows file names. - pathString = pathString.replacingOccurrences(of: ":", with: "_") - #endif - guard !pathString.isEmpty else { + print("XXXXXXXXXXX - 4") throw ZipError.unzipFail } @@ -114,10 +113,11 @@ public class Zip { pathString = pathString.replacingOccurrences(of: "\\", with: "/") } - let fullPath = destination.appendingPathComponent(pathString).standardizedFileURL.path + let fullPath = destination.appendingPathComponent(pathString).standardizedFileURL.withUnsafeFileSystemRepresentation { String(cString: $0!) } // `.standardizedFileURL` removes any `..` to move a level up. // If we then check that the `fullPath` starts with the destination directory we know we are not extracting "outside" the destination. guard fullPath.starts(with: destination.standardizedFileURL.path) else { + print("XXXXXXXXXXX - 5") throw ZipError.unzipFail } @@ -140,6 +140,7 @@ public class Zip { let readBytes = unzReadCurrentFile(zip, &buffer, bufferSize) guard readBytes > 0 else { break } guard fwrite(buffer, Int(readBytes), 1, filePointer) == 1 else { + print("XXXXXXXXXXX - 6") throw ZipError.unzipFail } writeBytes += UInt64(readBytes) @@ -148,9 +149,11 @@ public class Zip { if let filePointer { fclose(filePointer) } if unzCloseCurrentFile(zip) == UNZ_CRCERROR { + print("XXXXXXXXXXX - 7") throw ZipError.unzipFail } guard writeBytes == fileInfo.uncompressed_size else { + print("XXXXXXXXXXX - 8") throw ZipError.unzipFail }