Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fwrite() and uncompressed_size validation #94

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion Zip/Zip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down