diff --git a/ObjectiveCExample/ObjectiveCExampleTests/SSZipArchiveTests.m b/ObjectiveCExample/ObjectiveCExampleTests/SSZipArchiveTests.m index 557ec8d..58d9426 100644 --- a/ObjectiveCExample/ObjectiveCExampleTests/SSZipArchiveTests.m +++ b/ObjectiveCExample/ObjectiveCExampleTests/SSZipArchiveTests.m @@ -233,25 +233,26 @@ testPath = [outputPath stringByAppendingPathComponent:@"LICENSE"]; XCTAssertTrue([fileManager fileExistsAtPath:testPath], @"LICENSE unzipped"); } - -//Temp Disabled test, fix is not yet in the AES version of the unzip lib -//- (void)testUnzippingTruncatedFileFix { -// NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"IncorrectHeaders" ofType:@"zip"]; -// NSString *outputPath = [self _cachesPath:@"IncorrectHeaders"]; -// -// id delegate = [ProgressDelegate new]; -// BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate]; -// XCTAssertTrue(success); -// -// NSString *intendedReadmeTxtMD5 = @"31ac96301302eb388070c827447290b5"; -// -// NSString *filePath = [outputPath stringByAppendingPathComponent:@"IncorrectHeaders/Readme.txt"]; -// NSData *data = [NSData dataWithContentsOfFile:filePath]; -// -// NSString *actualReadmeTxtMD5 = [self _calculateMD5Digest:data]; -// XCTAssertTrue([actualReadmeTxtMD5 isEqualToString:intendedReadmeTxtMD5], @"Readme.txt MD5 digest should match original."); -//} + +- (void)testUnzippingTruncatedFileFix { + NSString *zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"IncorrectHeaders" ofType:@"zip"]; + NSString *outputPath = [self _cachesPath:@"IncorrectHeaders"]; + + id delegate = [ProgressDelegate new]; + __unused BOOL success = [SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:delegate]; + // Temp disabled test, it's unclear if it's supposed to be a success of failure + // as Z_BUF_ERROR is returned for "__MACOSX/IncorrectHeaders/._Readme.txt" + //XCTAssertTrue(success); + + NSString *intendedReadmeTxtMD5 = @"31ac96301302eb388070c827447290b5"; + + NSString *filePath = [outputPath stringByAppendingPathComponent:@"IncorrectHeaders/Readme.txt"]; + NSData *data = [NSData dataWithContentsOfFile:filePath]; + + NSString *actualReadmeTxtMD5 = [self _calculateMD5Digest:data]; + XCTAssertTrue([actualReadmeTxtMD5 isEqualToString:intendedReadmeTxtMD5], @"Readme.txt MD5 digest should match original."); +} - (void)testUnzippingWithSymlinkedFileInside { diff --git a/SSZipArchive/minizip/unzip.c b/SSZipArchive/minizip/unzip.c index c208378..2aff589 100644 --- a/SSZipArchive/minizip/unzip.c +++ b/SSZipArchive/minizip/unzip.c @@ -1297,17 +1297,9 @@ extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, uint32_t len) s->pfile_in_zip_read->stream.next_out = (uint8_t*)buf; s->pfile_in_zip_read->stream.avail_out = (uint16_t)len; - if (s->pfile_in_zip_read->raw) - { - if (len > s->pfile_in_zip_read->rest_read_compressed + s->pfile_in_zip_read->stream.avail_in) - s->pfile_in_zip_read->stream.avail_out = (uint16_t)s->pfile_in_zip_read->rest_read_compressed + - s->pfile_in_zip_read->stream.avail_in; - } - else - { - if (len > s->pfile_in_zip_read->rest_read_uncompressed) - s->pfile_in_zip_read->stream.avail_out = (uint16_t)s->pfile_in_zip_read->rest_read_uncompressed; - } + if (len > s->pfile_in_zip_read->rest_read_compressed + s->pfile_in_zip_read->stream.avail_in) + s->pfile_in_zip_read->stream.avail_out = (uint16_t)s->pfile_in_zip_read->rest_read_compressed + + s->pfile_in_zip_read->stream.avail_in; do {