Merge pull request #363 from ibsh/master

Handle zero-length arguments
This commit is contained in:
Joshua Hudson
2017-08-01 20:10:45 -07:00
committed by GitHub
2 changed files with 18 additions and 1 deletions

View File

@@ -21,6 +21,7 @@ typedef NS_ENUM(NSInteger, SSZipArchiveErrorCode) {
SSZipArchiveErrorCodeFileInfoNotLoadable = -3,
SSZipArchiveErrorCodeFileContentNotReadable = -4,
SSZipArchiveErrorCodeFailedToWriteFile = -5,
SSZipArchiveErrorCodeInvalidArguments = -6,
};
@protocol SSZipArchiveDelegate;

View File

@@ -184,12 +184,28 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
toDestination:(NSString *)destination
preserveAttributes:(BOOL)preserveAttributes
overwrite:(BOOL)overwrite
password:(NSString *)password
password:(nullable NSString *)password
error:(NSError **)error
delegate:(id<SSZipArchiveDelegate>)delegate
progressHandler:(void (^)(NSString *entry, unz_file_info zipInfo, long entryNumber, long total))progressHandler
completionHandler:(void (^)(NSString *path, BOOL succeeded, NSError * __nullable error))completionHandler
{
// Guard against empty strings
if ([path length] == 0 || [destination length] == 0)
{
NSDictionary *userInfo = @{NSLocalizedDescriptionKey: @"received invalid argument(s)"};
NSError *err = [NSError errorWithDomain:SSZipArchiveErrorDomain code:SSZipArchiveErrorCodeInvalidArguments userInfo:userInfo];
if (error)
{
*error = err;
}
if (completionHandler)
{
completionHandler(nil, NO, err);
}
}
// Begin opening
zipFile zip = unzOpen((const char*)[path fileSystemRepresentation]);
if (zip == NULL)