Skip to content

Commit b35fa71

Browse files
committed
bump support for minizip to 3.0.6
1 parent 203aa68 commit b35fa71

File tree

15 files changed

+132
-61
lines changed

15 files changed

+132
-61
lines changed

.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- SSZipArchive (2.5.0)
2+
- SSZipArchive (2.5.1)
33

44
DEPENDENCIES:
55
- SSZipArchive (from `..`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
99
:path: ".."
1010

1111
SPEC CHECKSUMS:
12-
SSZipArchive: 47b4ac3dbcb37e319bde9dd3a706f627de1d77d3
12+
SSZipArchive: 838576d09fe0196781dacb1c589d193604d22353
1313

1414
PODFILE CHECKSUM: 570af5c3534cb262ca98be3dedfff7caa40f00ed
1515

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ let package = Package(
2424
.define("HAVE_STDINT_H"),
2525
.define("HAVE_WZAES"),
2626
.define("HAVE_ZLIB"),
27+
.define("ZLIB_COMPAT")
2728
],
2829
linkerSettings: [
2930
.linkedLibrary("z"),

Release-Instructions.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,23 @@ The following steps should be taken by project maintainers when they update mini
3030
2. Have cmake:
3131
`brew install cmake`
3232
3. Run cmake on minizip repo with our desired configuration:
33-
`cmake . -DMZ_BZIP2=OFF -DMZ_LZMA=OFF`
33+
`cmake . -DMZ_BZIP2=OFF -DMZ_LZMA=OFF -DMZ_ZLIB=ON -DMZ_LIBCOMP=OFF`
3434
4. Look at the file `./CMakeFiles/minizip.dir/DependInfo.cmake` it will give you the following information:
3535
- The list of C files that we need to include.
3636

37-
Note: It will suggest we include libcomp and that only works on macos 10.11 and up, so the .c and .h file should not be included until we bump the min os versions.
38-
3937
5. Look at the file `./CMakeFiles/minizip.dir/flags.make` it will give you the following information:
4038

41-
- The list of compiler flags that we need to include
39+
- The list of compiler flags that we need to include (as of minizip 3.0.5 we have to include either zlib-ng OR ZLIB_COMPAT)
4240

4341
Note: These should not be changed unless you have issues compiling or we bump the min os versions.
4442

45-
HAVE_INTTYPES_H HAVE_PKCRYPT HAVE_STDINT_H HAVE_WZAES HAVE_ZLIB
43+
HAVE_INTTYPES_H HAVE_PKCRYPT HAVE_STDINT_H HAVE_WZAES HAVE_ZLIB ZLIB_COMPAT
4644

4745
With the exception of the last two: "MZ_ZIP_SIGNING" "_POSIX_C_SOURCE=200112L"
4846

49-
With later version of minizip it will want to switch to libcomp it will suggest we include libcomp and that only works on macos 10.11 and up.
5047

5148
6. Set those flags in SSZipArchive.podspec (for CocoaPods) and in ZipArchive.xcodeproj (for Carthage)
49+
5250
7. Replace the .h and .c files with the latest ones, except for `mz_compat.h`, which is customized to expose some struct in SSZipCommon.h and to provide support for optional aes.
5351

54-
Note: we can also use `cmake -G Xcode . -DMZ_BZIP2=OFF -DMZ_LZMA=OFF` to get the list of files to include in an xcodeproj of its own, from where we can remove unneeded `zip.h` and `unzip.h`.
52+
Note: we can also use `cmake -G Xcode . -DMZ_BZIP2=OFF -DMZ_LZMA=OFF -DMZ_ZLIB=ON -DMZ_LIBCOMP=OFF` to get the list of files to include in an xcodeproj of its own, from where we can remove unneeded `zip.h` and `unzip.h`.

SSZipArchive.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'SSZipArchive'
3-
s.version = '2.5.0'
3+
s.version = '2.5.1'
44
s.summary = 'Utility class for zipping and unzipping files on iOS, tvOS, watchOS, and macOS.'
55
s.description = 'SSZipArchive is a simple utility class for zipping and unzipping files on iOS, tvOS, watchOS, and macOS. It supports AES and PKWARE encryption.'
66
s.homepage = 'https://github.com/ZipArchive/ZipArchive'
@@ -16,5 +16,5 @@ Pod::Spec.new do |s|
1616
s.libraries = 'z', 'iconv'
1717
s.framework = 'Security'
1818
s.pod_target_xcconfig = { 'DEFINES_MODULE' => 'YES',
19-
'GCC_PREPROCESSOR_DEFINITIONS' => 'HAVE_INTTYPES_H HAVE_PKCRYPT HAVE_STDINT_H HAVE_WZAES HAVE_ZLIB' }
19+
'GCC_PREPROCESSOR_DEFINITIONS' => 'HAVE_INTTYPES_H HAVE_PKCRYPT HAVE_STDINT_H HAVE_WZAES HAVE_ZLIB ZLIB_COMPAT' }
2020
end

SSZipArchive/minizip/mz.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
/***************************************************************************/
1515

1616
/* MZ_VERSION */
17-
#define MZ_VERSION ("3.0.4")
18-
#define MZ_VERSION_BUILD (030004)
17+
#define MZ_VERSION ("3.0.6")
18+
#define MZ_VERSION_BUILD (030006)
1919

2020
/* MZ_ERROR */
2121
#define MZ_OK (0) /* zlib */
@@ -126,8 +126,14 @@
126126
#define MZ_HASH_MD5_SIZE (16)
127127
#define MZ_HASH_SHA1 (20)
128128
#define MZ_HASH_SHA1_SIZE (20)
129+
#define MZ_HASH_SHA224 (22)
130+
#define MZ_HASH_SHA224_SIZE (28)
129131
#define MZ_HASH_SHA256 (23)
130132
#define MZ_HASH_SHA256_SIZE (32)
133+
#define MZ_HASH_SHA384 (24)
134+
#define MZ_HASH_SHA384_SIZE (48)
135+
#define MZ_HASH_SHA512 (25)
136+
#define MZ_HASH_SHA512_SIZE (64)
131137
#define MZ_HASH_MAX_SIZE (256)
132138

133139
/* MZ_ENCODING */

SSZipArchive/minizip/mz_crypt.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,17 @@
1414
#include "mz_crypt.h"
1515

1616
#if defined(HAVE_ZLIB)
17-
# include "zlib.h"
18-
# if defined(ZLIBNG_VERNUM) && !defined(ZLIB_COMPAT)
17+
# if !defined(ZLIB_COMPAT)
1918
# include "zlib-ng.h"
19+
# define ZLIB_PREFIX(x) zng_ ## x
20+
# else
21+
# include "zlib.h"
22+
# define ZLIB_PREFIX(x) x
2023
# endif
2124
#elif defined(HAVE_LZMA)
2225
# include "lzma.h"
2326
#endif
2427

25-
/***************************************************************************/
26-
/* Define z_crc_t in zlib 1.2.5 and less or if using zlib-ng */
27-
28-
#if defined(HAVE_ZLIB) && defined(ZLIBNG_VERNUM)
29-
# if defined(ZLIB_COMPAT)
30-
# define ZLIB_PREFIX(x) x
31-
# else
32-
# define ZLIB_PREFIX(x) zng_ ## x
33-
# endif
34-
typedef uint32_t z_crc_t;
35-
#elif defined(HAVE_ZLIB)
36-
# define ZLIB_PREFIX(x) x
37-
# if (ZLIB_VERNUM < 0x1270)
38-
typedef unsigned long z_crc_t;
39-
# endif
40-
#endif
41-
4228
/***************************************************************************/
4329

4430
#if defined(MZ_ZIP_NO_CRYPTO)
@@ -49,6 +35,12 @@ int32_t mz_crypt_rand(uint8_t *buf, int32_t size) {
4935

5036
uint32_t mz_crypt_crc32_update(uint32_t value, const uint8_t *buf, int32_t size) {
5137
#if defined(HAVE_ZLIB)
38+
/* Define z_crc_t in zlib 1.2.5 and less or if using zlib-ng */
39+
# if (ZLIB_VERNUM < 0x1270)
40+
typedef unsigned long z_crc_t;
41+
# else
42+
typedef uint32_t z_crc_t;
43+
# endif
5244
return (uint32_t)ZLIB_PREFIX(crc32)((z_crc_t)value, buf, (uInt)size);
5345
#elif defined(HAVE_LZMA)
5446
return (uint32_t)lzma_crc32(buf, (size_t)size, (uint32_t)value);

SSZipArchive/minizip/mz_crypt_apple.c

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,25 @@ int32_t mz_crypt_rand(uint8_t *buf, int32_t size) {
2929
/***************************************************************************/
3030

3131
typedef struct mz_crypt_sha_s {
32-
CC_SHA1_CTX ctx1;
33-
CC_SHA256_CTX ctx256;
34-
int32_t error;
35-
int32_t initialized;
36-
uint16_t algorithm;
32+
union {
33+
CC_SHA1_CTX ctx1;
34+
CC_SHA256_CTX ctx256;
35+
CC_SHA512_CTX ctx512;
36+
};
37+
int32_t error;
38+
int32_t initialized;
39+
uint16_t algorithm;
3740
} mz_crypt_sha;
3841

3942
/***************************************************************************/
4043

44+
static const uint8_t mz_crypt_sha_digest_size[] = {
45+
MZ_HASH_SHA1_SIZE, 0, MZ_HASH_SHA224_SIZE,
46+
MZ_HASH_SHA256_SIZE, MZ_HASH_SHA384_SIZE, MZ_HASH_SHA512_SIZE
47+
};
48+
49+
/***************************************************************************/
50+
4151
void mz_crypt_sha_reset(void *handle) {
4252
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
4353

@@ -53,12 +63,25 @@ int32_t mz_crypt_sha_begin(void *handle) {
5363

5464
mz_crypt_sha_reset(handle);
5565

56-
if (sha->algorithm == MZ_HASH_SHA1)
66+
switch (sha->algorithm) {
67+
case MZ_HASH_SHA1:
5768
sha->error = CC_SHA1_Init(&sha->ctx1);
58-
else if (sha->algorithm == MZ_HASH_SHA256)
69+
break;
70+
case MZ_HASH_SHA224:
71+
sha->error = CC_SHA224_Init(&sha->ctx256);
72+
break;
73+
case MZ_HASH_SHA256:
5974
sha->error = CC_SHA256_Init(&sha->ctx256);
60-
else
75+
break;
76+
case MZ_HASH_SHA384:
77+
sha->error = CC_SHA384_Init(&sha->ctx512);
78+
break;
79+
case MZ_HASH_SHA512:
80+
sha->error = CC_SHA512_Init(&sha->ctx512);
81+
break;
82+
default:
6183
return MZ_PARAM_ERROR;
84+
}
6285

6386
if (!sha->error)
6487
return MZ_HASH_ERROR;
@@ -73,10 +96,23 @@ int32_t mz_crypt_sha_update(void *handle, const void *buf, int32_t size) {
7396
if (sha == NULL || buf == NULL || !sha->initialized)
7497
return MZ_PARAM_ERROR;
7598

76-
if (sha->algorithm == MZ_HASH_SHA1)
99+
switch (sha->algorithm) {
100+
case MZ_HASH_SHA1:
77101
sha->error = CC_SHA1_Update(&sha->ctx1, buf, size);
78-
else
102+
break;
103+
case MZ_HASH_SHA224:
104+
sha->error = CC_SHA224_Update(&sha->ctx256, buf, size);
105+
break;
106+
case MZ_HASH_SHA256:
79107
sha->error = CC_SHA256_Update(&sha->ctx256, buf, size);
108+
break;
109+
case MZ_HASH_SHA384:
110+
sha->error = CC_SHA384_Update(&sha->ctx512, buf, size);
111+
break;
112+
case MZ_HASH_SHA512:
113+
sha->error = CC_SHA512_Update(&sha->ctx512, buf, size);
114+
break;
115+
}
80116

81117
if (!sha->error)
82118
return MZ_HASH_ERROR;
@@ -89,15 +125,25 @@ int32_t mz_crypt_sha_end(void *handle, uint8_t *digest, int32_t digest_size) {
89125

90126
if (sha == NULL || digest == NULL || !sha->initialized)
91127
return MZ_PARAM_ERROR;
128+
if (digest_size < mz_crypt_sha_digest_size[sha->algorithm - MZ_HASH_SHA1])
129+
return MZ_PARAM_ERROR;
92130

93-
if (sha->algorithm == MZ_HASH_SHA1) {
94-
if (digest_size < MZ_HASH_SHA1_SIZE)
95-
return MZ_BUF_ERROR;
131+
switch (sha->algorithm) {
132+
case MZ_HASH_SHA1:
96133
sha->error = CC_SHA1_Final(digest, &sha->ctx1);
97-
} else {
98-
if (digest_size < MZ_HASH_SHA256_SIZE)
99-
return MZ_BUF_ERROR;
134+
break;
135+
case MZ_HASH_SHA224:
136+
sha->error = CC_SHA224_Final(digest, &sha->ctx256);
137+
break;
138+
case MZ_HASH_SHA256:
100139
sha->error = CC_SHA256_Final(digest, &sha->ctx256);
140+
break;
141+
case MZ_HASH_SHA384:
142+
sha->error = CC_SHA384_Final(digest, &sha->ctx512);
143+
break;
144+
case MZ_HASH_SHA512:
145+
sha->error = CC_SHA512_Final(digest, &sha->ctx512);
146+
break;
101147
}
102148

103149
if (!sha->error)
@@ -108,7 +154,8 @@ int32_t mz_crypt_sha_end(void *handle, uint8_t *digest, int32_t digest_size) {
108154

109155
void mz_crypt_sha_set_algorithm(void *handle, uint16_t algorithm) {
110156
mz_crypt_sha *sha = (mz_crypt_sha *)handle;
111-
sha->algorithm = algorithm;
157+
if (MZ_HASH_SHA1 <= algorithm && algorithm <= MZ_HASH_SHA512)
158+
sha->algorithm = algorithm;
112159
}
113160

114161
void *mz_crypt_sha_create(void **handle) {

SSZipArchive/minizip/mz_os.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ int32_t mz_path_combine(char *path, const char *join, int32_t max_path) {
3333
path[max_path - 1] = 0;
3434
} else {
3535
mz_path_append_slash(path, max_path, MZ_PATH_SLASH_PLATFORM);
36-
strncat(path, join, max_path - path_len);
36+
path_len = (int32_t)strlen(path);
37+
if (max_path > path_len)
38+
strncat(path, join, max_path - path_len - 1);
3739
}
3840

3941
return MZ_OK;
@@ -277,17 +279,17 @@ int32_t mz_path_get_filename(const char *path, const char **filename) {
277279

278280
int32_t mz_dir_make(const char *path) {
279281
int32_t err = MZ_OK;
280-
int16_t len = 0;
282+
size_t len = 0;
281283
char *current_dir = NULL;
282284
char *match = NULL;
283285
char hold = 0;
284286

285287

286-
len = (int16_t)strlen(path);
287-
if (len <= 0)
288+
len = strlen(path);
289+
if (len <= 0 || len > INT16_MAX)
288290
return 0;
289291

290-
current_dir = (char *)MZ_ALLOC((uint16_t)len + 1);
292+
current_dir = (char *)MZ_ALLOC(len + 1);
291293
if (current_dir == NULL)
292294
return MZ_MEM_ERROR;
293295

SSZipArchive/minizip/mz_os_posix.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ int32_t mz_os_get_file_date(const char *path, time_t *modified_date, time_t *acc
222222
/* Not all systems allow stat'ing a file with / appended */
223223
len = strlen(path);
224224
name = (char *)malloc(len + 1);
225-
strncpy(name, path, len + 1);
225+
strncpy(name, path, len);
226+
name[len - 1] = 0;
226227
mz_path_remove_slash(name);
227228

228229
if (stat(name, &path_stat) == 0) {

SSZipArchive/minizip/mz_strm_zlib.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@
1313
#include "mz_strm.h"
1414
#include "mz_strm_zlib.h"
1515

16-
#include "zlib.h"
17-
#if defined(ZLIBNG_VERNUM) && !defined(ZLIB_COMPAT)
16+
#if !defined(ZLIB_COMPAT)
1817
# include "zlib-ng.h"
18+
#else
19+
# include "zlib.h"
1920
#endif
2021

2122
/***************************************************************************/
2223

23-
#if defined(ZLIBNG_VERNUM) && !defined(ZLIB_COMPAT)
24+
#if !defined(ZLIB_COMPAT)
2425
# define ZLIB_PREFIX(x) zng_ ## x
2526
typedef zng_stream zlib_stream;
2627
#else

SSZipArchive/minizip/mz_zip.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,6 +2230,16 @@ int32_t mz_zip_entry_seek_local_header(void *handle) {
22302230
return mz_stream_seek(zip->stream, zip->file_info.disk_offset + zip->disk_offset_shift, MZ_SEEK_SET);
22312231
}
22322232

2233+
int32_t mz_zip_entry_get_compress_stream(void *handle, void **compress_stream) {
2234+
mz_zip *zip = (mz_zip *)handle;
2235+
if (zip == NULL || compress_stream == NULL)
2236+
return MZ_PARAM_ERROR;
2237+
*compress_stream = zip->compress_stream;
2238+
if (*compress_stream == NULL)
2239+
return MZ_EXIST_ERROR;
2240+
return MZ_OK;
2241+
}
2242+
22332243
int32_t mz_zip_entry_close(void *handle) {
22342244
return mz_zip_entry_close_raw(handle, UINT64_MAX, 0);
22352245
}

SSZipArchive/minizip/mz_zip.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ int32_t mz_zip_entry_write_close(void *handle, uint32_t crc32, int64_t compresse
139139
int32_t mz_zip_entry_seek_local_header(void *handle);
140140
/* Seeks to the local header for the entry */
141141

142+
int32_t mz_zip_entry_get_compress_stream(void *handle, void **compress_stream);
143+
/* Get a pointer to the compression stream used for the current entry */
144+
142145
int32_t mz_zip_entry_close_raw(void *handle, int64_t uncompressed_size, uint32_t crc32);
143146
/* Close the current file in the zip file where raw is compressed data */
144147

SSZipArchive/minizip/mz_zip_rw.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ int32_t mz_zip_reader_close(void *handle) {
211211
mz_stream_os_delete(&reader->file_stream);
212212

213213
if (reader->mem_stream != NULL) {
214-
mz_stream_mem_close(reader->mem_stream);
215-
mz_stream_mem_delete(&reader->mem_stream);
214+
mz_stream_close(reader->mem_stream);
215+
mz_stream_delete(&reader->mem_stream);
216216
}
217217

218218
return err;
@@ -1143,7 +1143,8 @@ int32_t mz_zip_writer_open_file(void *handle, const char *path, int64_t disk_siz
11431143

11441144
/* Create destination directory if it doesn't already exist */
11451145
if (strchr(path, '/') != NULL || strrchr(path, '\\') != NULL) {
1146-
strncpy(directory, path, sizeof(directory));
1146+
strncpy(directory, path, sizeof(directory) - 1);
1147+
directory[sizeof(directory) - 1] = 0;
11471148
mz_path_remove_filename(directory);
11481149
if (mz_os_file_exists(directory) != MZ_OK)
11491150
mz_dir_make(directory);

0 commit comments

Comments
 (0)