diff --git a/Zip/Zip.swift b/Zip/Zip.swift index 298f99f789a2b9eefb631039905159b1baf90e55..a6fc472229e64ceb519b854a2b9712aa06502712 100644 --- a/Zip/Zip.swift +++ b/Zip/Zip.swift @@ -187,12 +187,17 @@ public class Zip { unzCloseCurrentFile(zip) ret = unzGoToNextFile(zip) } + + var writeBytes: UInt64 = 0 var filePointer: UnsafeMutablePointer? filePointer = fopen(fullPath, "wb") while filePointer != nil { let readBytes = unzReadCurrentFile(zip, &buffer, bufferSize) if readBytes > 0 { - fwrite(buffer, Int(readBytes), 1, filePointer) + guard fwrite(buffer, Int(readBytes), 1, filePointer) == 1 else { + throw ZipError.unzipFail + } + writeBytes += UInt64(readBytes) } else { break @@ -204,6 +209,9 @@ public class Zip { if crc_ret == UNZ_CRCERROR { throw ZipError.unzipFail } + guard writeBytes == fileInfo.uncompressed_size else { + throw ZipError.unzipFail + } //Set file permissions from current fileInfo if fileInfo.external_fa != 0 {