report error for negative readBytes (invalid password)

This commit is contained in:
Antoine Cœur
2017-10-04 20:21:07 +08:00
parent 6bf9406cff
commit b7097ae6bb
2 changed files with 20 additions and 3 deletions
@@ -186,7 +186,7 @@
NSError *error = nil;
BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath overwrite:YES password:@"passw0rd123" error:&error delegate:self];
XCTAssertTrue(success);
XCTAssertFalse(success);
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *testPath = [outputPath stringByAppendingPathComponent:@"Readme.markdown"];
+19 -2
View File
@@ -116,7 +116,8 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
unsigned char buffer[10] = {0};
int readBytes = unzReadCurrentFile(zip, buffer, (unsigned)MIN(10UL,fileInfo.uncompressed_size));
if (readBytes < 0) {
// Let's assume the invalid password caused this error
// Let's assume error Z_DATA_ERROR is caused by an invalid password
// Let's assume other errors are caused by Content Not Readable
if (readBytes != Z_DATA_ERROR) {
if (error) {
*error = [NSError errorWithDomain:SSZipArchiveErrorDomain
@@ -451,6 +452,11 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
break;
}
readBytes = unzReadCurrentFile(zip, buffer, 4096);
if (readBytes < 0) {
// Let's assume error Z_DATA_ERROR is caused by an invalid password
// Let's assume other errors are caused by Content Not Readable
success = NO;
}
}
if (fp) {
@@ -511,6 +517,11 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
break;
}
}
} else {
// Let's assume error Z_DATA_ERROR is caused by an invalid password
// Let's assume other errors are caused by Content Not Readable
success = NO;
break;
}
}
else
@@ -520,9 +531,15 @@ NSString *const SSZipArchiveErrorDomain = @"SSZipArchiveErrorDomain";
int bytesRead = 0;
while ((bytesRead = unzReadCurrentFile(zip, buffer, 4096)) > 0)
{
buffer[bytesRead] = (int)0;
buffer[bytesRead] = 0;
[destinationPath appendString:@((const char *)buffer)];
}
if (bytesRead < 0) {
// Let's assume error Z_DATA_ERROR is caused by an invalid password
// Let's assume other errors are caused by Content Not Readable
success = NO;
break;
}
// Check if the symlink exists and delete it if we're overwriting
if (overwrite)