Compare commits
29 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a311e60107 | ||
|
|
69fb8f4a4c | ||
|
|
1d163e4db5 | ||
|
|
3f5a7b30dc | ||
|
|
bdbab4d3b3 | ||
|
|
fdb1726299 | ||
|
|
709006228c | ||
|
|
db0c62c481 | ||
|
|
d9ea638369 | ||
|
|
f18a98e551 | ||
|
|
557e869222 | ||
|
|
26630b36af | ||
|
|
581adbb98c | ||
|
|
d646bf93a2 | ||
|
|
b7598bc95f | ||
|
|
236fcb7d65 | ||
|
|
a46e35e2b8 | ||
|
|
e171229257 | ||
|
|
3a87f3ccfa | ||
|
|
df4ffca706 | ||
|
|
64c542e090 | ||
|
|
f900d38036 | ||
|
|
9070c825f8 | ||
|
|
bfc0904d14 | ||
|
|
45009d71e7 | ||
|
|
b27c74b04c | ||
|
|
b6f7f605fe | ||
|
|
f6eb58cc51 | ||
|
|
5651fb2c1b |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@
|
||||
*.perspectivev3
|
||||
*.xcworkspace
|
||||
xcuserdata
|
||||
DerivedData
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
# SSZipArchive Changelog
|
||||
|
||||
### Version 0.2.1
|
||||
|
||||
[Released May 9, 2012](https://github.com/samsoffes/sskeychain/tree/0.2.1)
|
||||
|
||||
* Support for symbolic links — [@jparishy](http://github.com/jparishy)
|
||||
* Fix several warnings
|
||||
|
||||
### Version 0.2.0
|
||||
|
||||
[Released May 7, 2012](https://github.com/samsoffes/sskeychain/tree/0.2.0)
|
||||
|
||||
* Add unzipping delegate
|
||||
* Add unzipping delegate — [@uppfinnarn](http://github.com/uppfinnarn)
|
||||
* Fix unzipping with passwords
|
||||
* Fix modified at dates
|
||||
* Fix modified at dates — [@brantsears](http://github.com/brantsears)
|
||||
* Fix truncated files. Ignore the zip headers and unzip until there is no more file. — [@jparishy](http://github.com/jparishy)
|
||||
|
||||
### Version 0.1.2
|
||||
|
||||
|
||||
2
LICENSE
2
LICENSE
@@ -1,4 +1,4 @@
|
||||
Copyright (c) 2010-2011 Sam Soffes
|
||||
Copyright (c) 2010-2013 Sam Soffes
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
@@ -8,12 +8,15 @@ SSZipArchive is a simple utility class for zipping and unzipping files. Features
|
||||
* Appending to zip files
|
||||
* Zipping files
|
||||
* Zipping NSData with a filename
|
||||
* Works in ARC and non-ARC projects
|
||||
|
||||
## Adding to your project
|
||||
|
||||
1. Add `SSZipArchive.h`, `SSZipArchive.m`, and `minizip` to your project.
|
||||
2. Add the `libz` library to your target
|
||||
|
||||
You don't need to do anything regarding ARC. SSZipArchive will detect if you're not using ARC and add the required memory management code.
|
||||
|
||||
## Usage
|
||||
|
||||
``` objective-c
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// SSZipArchive
|
||||
//
|
||||
// Created by Sam Soffes on 7/21/10.
|
||||
// Copyright (c) Sam Soffes 2010-2011. All rights reserved.
|
||||
// Copyright (c) Sam Soffes 2010-2013. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
124
SSZipArchive.m
124
SSZipArchive.m
@@ -3,7 +3,7 @@
|
||||
// SSZipArchive
|
||||
//
|
||||
// Created by Sam Soffes on 7/21/10.
|
||||
// Copyright (c) Sam Soffes 2010-2011. All rights reserved.
|
||||
// Copyright (c) Sam Soffes 2010-2013. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SSZipArchive.h"
|
||||
@@ -11,6 +11,8 @@
|
||||
#import "zlib.h"
|
||||
#import "zconf.h"
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#define CHUNK 16384
|
||||
|
||||
@interface SSZipArchive ()
|
||||
@@ -105,11 +107,37 @@
|
||||
[delegate zipArchiveWillUnzipFileAtIndex:currentFileNumber totalFiles:(NSInteger)globalInfo.number_entry
|
||||
archivePath:path fileInfo:fileInfo];
|
||||
}
|
||||
|
||||
|
||||
char *filename = (char *)malloc(fileInfo.size_filename + 1);
|
||||
unzGetCurrentFileInfo(zip, &fileInfo, filename, fileInfo.size_filename + 1, NULL, 0, NULL, 0);
|
||||
filename[fileInfo.size_filename] = '\0';
|
||||
|
||||
|
||||
//
|
||||
// NOTE
|
||||
// I used the ZIP spec from here:
|
||||
// http://www.pkware.com/documents/casestudies/APPNOTE.TXT
|
||||
//
|
||||
// ...to deduce this method of detecting whether the file in the ZIP is a symbolic link.
|
||||
// If it is, it is listed as a directory but has a data size greater than zero (real
|
||||
// directories have it equal to 0) and the included, uncompressed data is the symbolic link path.
|
||||
//
|
||||
// ZIP files did not originally include support for symbolic links so the specification
|
||||
// doesn't include anything in them that isn't part of a unix extension that isn't being used
|
||||
// by the archivers we're testing. Most of this is figured out through trial and error and
|
||||
// reading ZIP headers in hex editors. This seems to do the trick though.
|
||||
//
|
||||
|
||||
const uLong ZipCompressionMethodStore = 0;
|
||||
|
||||
BOOL fileIsSymbolicLink = NO;
|
||||
|
||||
if((fileInfo.compression_method == ZipCompressionMethodStore) && // Is it compressed?
|
||||
(S_ISDIR(fileInfo.external_fa)) && // Is it marked as a directory
|
||||
(fileInfo.compressed_size > 0)) // Is there any data?
|
||||
{
|
||||
fileIsSymbolicLink = YES;
|
||||
}
|
||||
|
||||
// Check if it contains directory
|
||||
NSString *strPath = [NSString stringWithCString:filename encoding:NSUTF8StringEncoding];
|
||||
BOOL isDirectory = NO;
|
||||
@@ -137,41 +165,72 @@
|
||||
NSLog(@"[SSZipArchive] Error: %@", err.localizedDescription);
|
||||
}
|
||||
|
||||
[directoriesModificationDates addObject: [NSDictionary dictionaryWithObjectsAndKeys:fullPath, @"path", modDate, @"modDate", nil]];
|
||||
if(!fileIsSymbolicLink)
|
||||
[directoriesModificationDates addObject: [NSDictionary dictionaryWithObjectsAndKeys:fullPath, @"path", modDate, @"modDate", nil]];
|
||||
|
||||
if ([fileManager fileExistsAtPath:fullPath] && !isDirectory && !overwrite) {
|
||||
unzCloseCurrentFile(zip);
|
||||
ret = unzGoToNextFile(zip);
|
||||
continue;
|
||||
}
|
||||
|
||||
FILE *fp = fopen((const char*)[fullPath UTF8String], "wb");
|
||||
while (fp) {
|
||||
int readBytes = unzReadCurrentFile(zip, buffer, 4096);
|
||||
|
||||
if(!fileIsSymbolicLink)
|
||||
{
|
||||
FILE *fp = fopen((const char*)[fullPath UTF8String], "wb");
|
||||
while (fp) {
|
||||
int readBytes = unzReadCurrentFile(zip, buffer, 4096);
|
||||
|
||||
if (readBytes > 0) {
|
||||
fwrite(buffer, readBytes, 1, fp );
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fp) {
|
||||
fclose(fp);
|
||||
|
||||
// Set the original datetime property
|
||||
if (fileInfo.dosDate != 0) {
|
||||
NSDate *orgDate = [[self class] _dateWithMSDOSFormat:(UInt32)fileInfo.dosDate];
|
||||
NSDictionary *attr = [NSDictionary dictionaryWithObject:orgDate forKey:NSFileModificationDate];
|
||||
|
||||
if (attr) {
|
||||
if ([fileManager setAttributes:attr ofItemAtPath:fullPath error:nil] == NO) {
|
||||
// Can't set attributes
|
||||
NSLog(@"[SSZipArchive] Failed to set attributes");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (readBytes > 0) {
|
||||
fwrite(buffer, readBytes, 1, fp );
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (fp) {
|
||||
fclose(fp);
|
||||
|
||||
// Set the original datetime property
|
||||
if (fileInfo.dosDate != 0) {
|
||||
NSDate *orgDate = [[self class] _dateWithMSDOSFormat:(UInt32)fileInfo.dosDate];
|
||||
NSDictionary *attr = [NSDictionary dictionaryWithObject:orgDate forKey:NSFileModificationDate];
|
||||
|
||||
if (attr) {
|
||||
if ([fileManager setAttributes:attr ofItemAtPath:fullPath error:nil] == NO) {
|
||||
// Can't set attributes
|
||||
NSLog(@"[SSZipArchive] Failed to set attributes");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get the path for the symbolic link
|
||||
|
||||
NSURL* symlinkURL = [NSURL fileURLWithPath:fullPath];
|
||||
NSMutableString* destinationPath = [NSMutableString string];
|
||||
|
||||
int bytesRead = 0;
|
||||
while((bytesRead = unzReadCurrentFile(zip, buffer, 4096)) > 0)
|
||||
{
|
||||
buffer[bytesRead] = 0;
|
||||
[destinationPath appendString:[NSString stringWithUTF8String:(const char*)buffer]];
|
||||
}
|
||||
|
||||
//NSLog(@"Symlinking to: %@", destinationPath);
|
||||
|
||||
NSURL* destinationURL = [NSURL fileURLWithPath:destinationPath];
|
||||
|
||||
// Create the symbolic link
|
||||
NSError* symlinkError = nil;
|
||||
[fileManager createSymbolicLinkAtURL:symlinkURL withDestinationURL:destinationURL error:&symlinkError];
|
||||
|
||||
if(symlinkError != nil)
|
||||
{
|
||||
NSLog(@"Failed to create symbolic link at \"%@\" to \"%@\". Error: %@", symlinkURL.absoluteString, destinationURL.absoluteString, symlinkError.localizedDescription);
|
||||
}
|
||||
}
|
||||
|
||||
unzCloseCurrentFile( zip );
|
||||
ret = unzGoToNextFile( zip );
|
||||
@@ -290,6 +349,7 @@
|
||||
|
||||
zipCloseFileInZip(_zip);
|
||||
free(buffer);
|
||||
fclose(input);
|
||||
return YES;
|
||||
}
|
||||
|
||||
@@ -301,7 +361,7 @@
|
||||
if (!data) {
|
||||
return NO;
|
||||
}
|
||||
zip_fileinfo zipInfo = {0};
|
||||
zip_fileinfo zipInfo = {{0,0,0,0,0,0},0,0,0};
|
||||
[self zipInfo:&zipInfo setDate:[NSDate date]];
|
||||
|
||||
zipOpenNewFileInZip(_zip, [filename UTF8String], &zipInfo, NULL, 0, NULL, 0, NULL, Z_DEFLATED, Z_DEFAULT_COMPRESSION);
|
||||
|
||||
15
SSZipArchive.podspec
Normal file
15
SSZipArchive.podspec
Normal file
@@ -0,0 +1,15 @@
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'SSZipArchive'
|
||||
s.version = '0.2.3'
|
||||
s.summary = 'Utility class for zipping and unzipping files on iOS and Mac.'
|
||||
s.description = 'SSZipArchive is a simple utility class for zipping and unzipping files on iOS and Mac.'
|
||||
s.homepage = 'https://github.com/soffes/ssziparchive'
|
||||
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
||||
s.author = { 'Sam Soffes' => 'sam@soff.es' }
|
||||
s.source = { :git => 'https://github.com/soffes/ssziparchive.git', :tag => '0.2.3' }
|
||||
s.ios.deployment_target = '4.0'
|
||||
s.osx.deployment_target = '10.6'
|
||||
s.source_files = 'SSZipArchive.{h,m}', 'minizip/*.{h,c}'
|
||||
s.preserve_paths = 'minizip'
|
||||
s.library = 'z'
|
||||
end
|
||||
BIN
Tests/IncorrectHeaders.zip
Normal file
BIN
Tests/IncorrectHeaders.zip
Normal file
Binary file not shown.
@@ -17,7 +17,10 @@
|
||||
B215FB6A143AD576003AC546 /* unzip.c in Sources */ = {isa = PBXBuildFile; fileRef = B215FB53143AD460003AC546 /* unzip.c */; };
|
||||
B215FB6B143AD576003AC546 /* zip.c in Sources */ = {isa = PBXBuildFile; fileRef = B215FB55143AD460003AC546 /* zip.c */; };
|
||||
B215FB6D143AD6FF003AC546 /* TestArchive.zip in Resources */ = {isa = PBXBuildFile; fileRef = B215FB6C143AD6FF003AC546 /* TestArchive.zip */; };
|
||||
B2283D5D155AD80F00F9395A /* Unicode.zip in Resources */ = {isa = PBXBuildFile; fileRef = B2283D5C155AD80F00F9395A /* Unicode.zip */; };
|
||||
B23FCC7F1558F1B70026375C /* TestPasswordArchive.zip in Resources */ = {isa = PBXBuildFile; fileRef = B23FCC7E1558F1B70026375C /* TestPasswordArchive.zip */; };
|
||||
C5AE4E64155A12760045F3ED /* IncorrectHeaders.zip in Resources */ = {isa = PBXBuildFile; fileRef = C5AE4E63155A12760045F3ED /* IncorrectHeaders.zip */; };
|
||||
C5AE4E6D155A8B010045F3ED /* SymbolicLink.zip in Resources */ = {isa = PBXBuildFile; fileRef = C5AE4E6C155A8B010045F3ED /* SymbolicLink.zip */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
@@ -39,7 +42,10 @@
|
||||
B215FB61143AD514003AC546 /* SSZipArchiveTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SSZipArchiveTests.m; sourceTree = "<group>"; };
|
||||
B215FB64143AD527003AC546 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
|
||||
B215FB6C143AD6FF003AC546 /* TestArchive.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = TestArchive.zip; sourceTree = "<group>"; };
|
||||
B2283D5C155AD80F00F9395A /* Unicode.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = Unicode.zip; sourceTree = "<group>"; };
|
||||
B23FCC7E1558F1B70026375C /* TestPasswordArchive.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = TestPasswordArchive.zip; sourceTree = "<group>"; };
|
||||
C5AE4E63155A12760045F3ED /* IncorrectHeaders.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = IncorrectHeaders.zip; sourceTree = "<group>"; };
|
||||
C5AE4E6C155A8B010045F3ED /* SymbolicLink.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = SymbolicLink.zip; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -114,10 +120,13 @@
|
||||
B215FB5E143AD505003AC546 /* SSZipArchiveTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B2283D5C155AD80F00F9395A /* Unicode.zip */,
|
||||
B215FB61143AD514003AC546 /* SSZipArchiveTests.m */,
|
||||
B215FB5F143AD514003AC546 /* SSZipArchiveTests-Info.plist */,
|
||||
C5AE4E63155A12760045F3ED /* IncorrectHeaders.zip */,
|
||||
B215FB6C143AD6FF003AC546 /* TestArchive.zip */,
|
||||
B23FCC7E1558F1B70026375C /* TestPasswordArchive.zip */,
|
||||
C5AE4E6C155A8B010045F3ED /* SymbolicLink.zip */,
|
||||
);
|
||||
name = SSZipArchiveTests;
|
||||
sourceTree = "<group>";
|
||||
@@ -176,6 +185,9 @@
|
||||
files = (
|
||||
B215FB6D143AD6FF003AC546 /* TestArchive.zip in Resources */,
|
||||
B23FCC7F1558F1B70026375C /* TestPasswordArchive.zip in Resources */,
|
||||
C5AE4E64155A12760045F3ED /* IncorrectHeaders.zip in Resources */,
|
||||
C5AE4E6D155A8B010045F3ED /* SymbolicLink.zip in Resources */,
|
||||
B2283D5D155AD80F00F9395A /* Unicode.zip in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -8,18 +8,21 @@
|
||||
|
||||
#import "SSZipArchive.h"
|
||||
#import <SenTestingKit/SenTestingKit.h>
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
|
||||
@interface SSZipArchiveTests : SenTestCase <SSZipArchiveDelegate>
|
||||
|
||||
- (NSString *)_cachesPath:(NSString *)directory;
|
||||
|
||||
- (NSString *)_calculateMD5Digest:(NSData *)data;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SSZipArchiveTests
|
||||
|
||||
- (void)setUp {
|
||||
[[NSFileManager defaultManager] removeItemAtPath:[self _cachesPath:nil] error:nil];
|
||||
}
|
||||
//- (void)setUp {
|
||||
// [[NSFileManager defaultManager] removeItemAtPath:[self _cachesPath:nil] error:nil];
|
||||
//}
|
||||
|
||||
|
||||
- (void)testZipping {
|
||||
@@ -66,6 +69,57 @@
|
||||
STAssertTrue([fileManager fileExistsAtPath:testPath], @"LICENSE unzipped");
|
||||
}
|
||||
|
||||
- (void)testUnzippingTruncatedFileFix {
|
||||
NSString* zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"IncorrectHeaders" ofType:@"zip"];
|
||||
NSString* outputPath = [self _cachesPath:@"IncorrectHeaders"];
|
||||
|
||||
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
|
||||
|
||||
NSString* intendedReadmeTxtMD5 = @"31ac96301302eb388070c827447290b5";
|
||||
|
||||
NSString* filePath = [outputPath stringByAppendingPathComponent:@"IncorrectHeaders/Readme.txt"];
|
||||
NSData* data = [NSData dataWithContentsOfFile:filePath];
|
||||
|
||||
NSString* actualReadmeTxtMD5 = [self _calculateMD5Digest:data];
|
||||
STAssertTrue([actualReadmeTxtMD5 isEqualToString:intendedReadmeTxtMD5], @"Readme.txt MD5 digest should match original.");
|
||||
}
|
||||
|
||||
- (void)testUnzippingWithSymlinkedFileInside {
|
||||
|
||||
NSString* zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"SymbolicLink" ofType:@"zip"];
|
||||
NSString* outputPath = [self _cachesPath:@"SymbolicLink"];
|
||||
|
||||
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
|
||||
|
||||
NSString *testSymlinkFolder = [outputPath stringByAppendingPathComponent:@"SymbolicLink/GitHub.app"];
|
||||
NSString *testSymlinkFile = [outputPath stringByAppendingPathComponent:@"SymbolicLink/Icon.icns"];
|
||||
|
||||
NSError *error = nil;
|
||||
NSString *symlinkFolderPath = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath:testSymlinkFolder error:&error];
|
||||
bool symbolicLinkToFolderPersists = ((symlinkFolderPath != nil) && [symlinkFolderPath isEqualToString:@"/Applications/GitHub.app"]) && (error == nil);
|
||||
|
||||
error = nil;
|
||||
|
||||
NSString *symlinkFilePath = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath:testSymlinkFile error:&error];
|
||||
bool symbolicLinkToFilePersists = ((symlinkFilePath != nil) && [symlinkFilePath isEqualToString:@"/Applications/GitHub.app/Contents/Resources/AppIcon.icns"]) && (error == nil);
|
||||
|
||||
STAssertTrue(symbolicLinkToFilePersists && symbolicLinkToFolderPersists, @"Symbolic links should persist from the original archive to the outputted files.");
|
||||
}
|
||||
|
||||
- (void)testUnzippingWithUnicodeFilenameInside {
|
||||
|
||||
NSString* zipPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"Unicode" ofType:@"zip"];
|
||||
NSString* outputPath = [self _cachesPath:@"Unicode"];
|
||||
|
||||
[SSZipArchive unzipFileAtPath:zipPath toDestination:outputPath delegate:self];
|
||||
|
||||
bool unicodeFilenameWasExtracted = [[NSFileManager defaultManager] fileExistsAtPath:[outputPath stringByAppendingPathComponent:@"Accént.txt"]];
|
||||
|
||||
bool unicodeFolderWasExtracted = [[NSFileManager defaultManager] fileExistsAtPath:[outputPath stringByAppendingPathComponent:@"Fólder/Nothing.txt"]];
|
||||
|
||||
STAssertTrue(unicodeFilenameWasExtracted, @"Files with filenames in unicode should be extracted properly.");
|
||||
STAssertTrue(unicodeFolderWasExtracted, @"Folders with names in unicode should be extracted propertly.");
|
||||
}
|
||||
|
||||
// Commented out to avoid checking in several gig file into the repository. Simply add a file named
|
||||
// `LargeArchive.zip` to the project and uncomment out these lines to test.
|
||||
@@ -117,4 +171,16 @@
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
// Taken from https://github.com/samsoffes/sstoolkit/blob/master/SSToolkit/NSData+SSToolkitAdditions.m
|
||||
- (NSString *)_calculateMD5Digest:(NSData *)data {
|
||||
unsigned char digest[CC_MD5_DIGEST_LENGTH], i;
|
||||
CC_MD5(data.bytes, (unsigned int)data.length, digest);
|
||||
NSMutableString *ms = [NSMutableString string];
|
||||
for (i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
|
||||
[ms appendFormat: @"%02x", (int)(digest[i])];
|
||||
}
|
||||
return [ms copy];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
BIN
Tests/SymbolicLink.zip
Normal file
BIN
Tests/SymbolicLink.zip
Normal file
Binary file not shown.
Binary file not shown.
BIN
Tests/Unicode.zip
Normal file
BIN
Tests/Unicode.zip
Normal file
Binary file not shown.
@@ -1629,7 +1629,7 @@ extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
|
||||
if (password != NULL)
|
||||
{
|
||||
int i;
|
||||
s->pcrc_32_tab = get_crc_table();
|
||||
s->pcrc_32_tab = (const unsigned long*)get_crc_table();
|
||||
init_keys(password,s->keys,s->pcrc_32_tab);
|
||||
if (ZSEEK64(s->z_filefunc, s->filestream,
|
||||
s->pfile_in_zip_read->pos_in_zipfile +
|
||||
@@ -1718,10 +1718,24 @@ extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
|
||||
|
||||
pfile_in_zip_read_info->stream.avail_out = (uInt)len;
|
||||
|
||||
// NOTE:
|
||||
// This bit of code seems to try to set the amount of space in the output buffer based on the
|
||||
// value stored in the headers stored in the .zip file. However, if those values are incorrect
|
||||
// it may result in a loss of data when uncompresssing that file. The compressed data is still
|
||||
// legit and will deflate without knowing the uncompressed code so this tidbit is unnecessary and
|
||||
// may cause issues for some .zip files.
|
||||
//
|
||||
// It's removed in here to fix those issues.
|
||||
//
|
||||
// See: https://github.com/samsoffes/ssziparchive/issues/16
|
||||
//
|
||||
|
||||
/*
|
||||
if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
|
||||
(!(pfile_in_zip_read_info->raw)))
|
||||
pfile_in_zip_read_info->stream.avail_out =
|
||||
(uInt)pfile_in_zip_read_info->rest_read_uncompressed;
|
||||
*/
|
||||
|
||||
if ((len>pfile_in_zip_read_info->rest_read_compressed+
|
||||
pfile_in_zip_read_info->stream.avail_in) &&
|
||||
|
||||
@@ -1250,7 +1250,7 @@ extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename,
|
||||
unsigned char bufHead[RAND_HEAD_LEN];
|
||||
unsigned int sizeHead;
|
||||
zi->ci.encrypt = 1;
|
||||
zi->ci.pcrc_32_tab = get_crc_table();
|
||||
zi->ci.pcrc_32_tab = (const unsigned long*)get_crc_table();
|
||||
/*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/
|
||||
|
||||
sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);
|
||||
|
||||
Reference in New Issue
Block a user