Commit 1ea5e961 authored by Shinichiro Oba's avatar Shinichiro Oba

Add fwrite() and uncompressed_size validation

parent 4a15a786
......@@ -180,12 +180,17 @@ public class Zip {
unzCloseCurrentFile(zip)
ret = unzGoToNextFile(zip)
}
var writeBytes: UInt64 = 0
var filePointer: UnsafeMutablePointer<FILE>?
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
......@@ -197,6 +202,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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment