Skip to content

Commit db558cd

Browse files
committed
minizip update: ioapi.h, qioapi.cpp, minizip_crypt.h
1 parent 9ed79a1 commit db558cd

File tree

4 files changed

+119
-188
lines changed

4 files changed

+119
-188
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
cmake-*
1111
CMakeUserPresets.json
1212
vcpkg_installed/
13-
Testing/
13+
Testing/
14+
minizip/

quazip/ioapi.h

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#ifndef _ZLIBIOAPI64_H
2424
#define _ZLIBIOAPI64_H
2525

26-
#if (!defined(_WIN32)) && (!defined(WIN32))
26+
#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
2727

2828
// Linux needs this to support file operation on files larger then 4+GB
2929
// But might need better if/def to select just the platforms that needs them.
@@ -40,6 +40,7 @@
4040
#ifndef _FILE_OFFSET_BIT
4141
#define _FILE_OFFSET_BIT 64
4242
#endif
43+
4344
#endif
4445

4546
#include <stdio.h>
@@ -51,6 +52,11 @@
5152
#define ftello64 ftell
5253
#define fseeko64 fseek
5354
#else
55+
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) || defined(MINIZIP_FOPEN_NO_64)
56+
#define fopen64 fopen
57+
#define ftello64 ftello
58+
#define fseeko64 fseeko
59+
#endif
5460
#ifdef _MSC_VER
5561
#define fopen64 fopen
5662
#if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
@@ -78,7 +84,7 @@
7884
#include "mz64conf.h"
7985
#endif
8086

81-
/* a type choosen by DEFINE */
87+
/* a type chosen by DEFINE */
8288
#ifdef HAVE_64BIT_INT_CUSTOM
8389
typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
8490
#else
@@ -88,6 +94,7 @@ typedef uint64_t ZPOS64_T;
8894
#else
8995

9096

97+
9198
#if defined(_MSC_VER) || defined(__BORLANDC__)
9299
typedef unsigned __int64 ZPOS64_T;
93100
#else
@@ -96,15 +103,15 @@ typedef unsigned long long int ZPOS64_T;
96103
#endif
97104
#endif
98105

99-
106+
/* Maximum unsigned 32-bit value used as placeholder for zip64 */
107+
#ifndef MAXU32
108+
#define MAXU32 (0xffffffff)
109+
#endif
100110

101111
#ifdef __cplusplus
102112
extern "C" {
103113
#endif
104114

105-
#ifndef OF
106-
#define OF _Z_OF
107-
#endif
108115

109116
#define ZLIB_FILEFUNC_SEEK_CUR (1)
110117
#define ZLIB_FILEFUNC_SEEK_END (2)
@@ -129,17 +136,17 @@ extern "C" {
129136

130137

131138

132-
typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, voidpf file, int mode));
133-
typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
134-
typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
135-
typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
136-
typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
139+
typedef voidpf (ZCALLBACK *open_file_func) (voidpf opaque, voidpf file, int mode);
140+
typedef uLong (ZCALLBACK *read_file_func) (voidpf opaque, voidpf stream, void* buf, uLong size);
141+
typedef uLong (ZCALLBACK *write_file_func) (voidpf opaque, voidpf stream, const void* buf, uLong size);
142+
typedef int (ZCALLBACK *close_file_func) (voidpf opaque, voidpf stream);
143+
typedef int (ZCALLBACK *testerror_file_func) (voidpf opaque, voidpf stream);
137144

138-
typedef uLong (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
139-
typedef int (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
145+
typedef long (ZCALLBACK *tell_file_func) (voidpf opaque, voidpf stream);
146+
typedef long (ZCALLBACK *seek_file_func) (voidpf opaque, voidpf stream, uLong offset, int origin);
140147

141148

142-
/* here is the "old" 32 bits structure structure */
149+
/* here is the "old" 32 bits structure */
143150
typedef struct zlib_filefunc_def_s
144151
{
145152
open_file_func zopen_file;
@@ -152,9 +159,9 @@ typedef struct zlib_filefunc_def_s
152159
voidpf opaque;
153160
} zlib_filefunc_def;
154161

155-
typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
156-
typedef int (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
157-
typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, voidpf file, int mode));
162+
typedef ZPOS64_T (ZCALLBACK *tell64_file_func) (voidpf opaque, voidpf stream);
163+
typedef long (ZCALLBACK *seek64_file_func) (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin);
164+
typedef voidpf (ZCALLBACK *open64_file_func) (voidpf opaque, voidpf file, int mode);
158165

159166
typedef struct zlib_filefunc64_def_s
160167
{
@@ -169,8 +176,8 @@ typedef struct zlib_filefunc64_def_s
169176
close_file_func zfakeclose_file; // for no-auto-close flag
170177
} zlib_filefunc64_def;
171178

172-
void fill_qiodevice64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
173-
void fill_qiodevice_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
179+
void fill_qiodevice64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def);
180+
void fill_qiodevice_filefunc (zlib_filefunc_def* pzlib_filefunc_def);
174181

175182
/* now internal definition, only for zip.c and unzip.h */
176183
typedef struct zlib_filefunc64_32_def_s
@@ -179,6 +186,7 @@ typedef struct zlib_filefunc64_32_def_s
179186
open_file_func zopen32_file;
180187
tell_file_func ztell32_file;
181188
seek_file_func zseek32_file;
189+
close_file_func zfakeclose_file; // for no-auto-close flag
182190
} zlib_filefunc64_32_def;
183191

184192

@@ -187,14 +195,14 @@ typedef struct zlib_filefunc64_32_def_s
187195
//#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
188196
//#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
189197
#define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
190-
#define ZFAKECLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zfakeclose_file)) ((filefunc).zfile_func64.opaque,filestream))
198+
#define ZFAKECLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zfakeclose_file)) ((filefunc).zfile_func64.opaque,filestream))
191199
#define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
192200

193-
voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf file,int mode));
194-
int call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
195-
ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
201+
voidpf call_zopen64(const zlib_filefunc64_32_def* pfilefunc,voidpf file,int mode);
202+
long call_zseek64(const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin);
203+
ZPOS64_T call_ztell64(const zlib_filefunc64_32_def* pfilefunc,voidpf filestream);
196204

197-
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
205+
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
198206

199207
#define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
200208
#define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))

quazip/minizip_crypt.h

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,25 @@
2727
Encryption is not supported.
2828
*/
2929

30-
#include "quazip_global.h"
31-
3230
#define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8))
3331

3432
/***********************************************************************
3533
* Return the next byte in the pseudo-random sequence
3634
*/
37-
static int decrypt_byte(unsigned long* pkeys, const z_crc_t FAR * pcrc_32_tab QUAZIP_UNUSED)
38-
{
39-
//(void) pcrc_32_tab; /* avoid "unused parameter" warning */
35+
static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab) {
4036
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
4137
* unpredictable manner on 16-bit systems; not a problem
4238
* with any known compiler so far, though */
4339

40+
(void)pcrc_32_tab;
4441
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
4542
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
4643
}
4744

4845
/***********************************************************************
4946
* Update the encryption keys with the next byte of plain text
5047
*/
51-
static int update_keys(unsigned long* pkeys,const z_crc_t FAR * pcrc_32_tab,int c)
52-
{
48+
static int update_keys(unsigned long* pkeys, const z_crc_t* pcrc_32_tab, int c) {
5349
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
5450
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
5551
(*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1;
@@ -65,8 +61,7 @@ static int update_keys(unsigned long* pkeys,const z_crc_t FAR * pcrc_32_tab,int
6561
* Initialize the encryption keys and the random header according to
6662
* the given password.
6763
*/
68-
static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t FAR * pcrc_32_tab)
69-
{
64+
static void init_keys(const char* passwd, unsigned long* pkeys, const z_crc_t* pcrc_32_tab) {
7065
*(pkeys+0) = 305419896L;
7166
*(pkeys+1) = 591751049L;
7267
*(pkeys+2) = 878082192L;
@@ -80,25 +75,23 @@ static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t FAR
8075
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
8176

8277
#define zencode(pkeys,pcrc_32_tab,c,t) \
83-
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
78+
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), (Byte)t^(c))
8479

8580
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
8681

8782
#define RAND_HEAD_LEN 12
8883
/* "last resort" source for second part of crypt seed pattern */
8984
# ifndef ZCR_SEED2
90-
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
85+
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
9186
# endif
9287

93-
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
94-
const char *passwd; /* password string */
95-
unsigned char *buf; /* where to write header */
96-
int bufSize;
97-
unsigned long* pkeys;
98-
const z_crc_t FAR * pcrc_32_tab;
99-
unsigned long crcForCrypting;
100-
{
101-
int n; /* index in random header */
88+
static unsigned crypthead(const char* passwd, /* password string */
89+
unsigned char* buf, /* where to write header */
90+
int bufSize,
91+
unsigned long* pkeys,
92+
const z_crc_t* pcrc_32_tab,
93+
unsigned long crcForCrypting) {
94+
unsigned n; /* index in random header */
10295
int t; /* temporary */
10396
int c; /* random byte */
10497
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
@@ -127,8 +120,8 @@ static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
127120
{
128121
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
129122
}
130-
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
131-
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
123+
buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
124+
buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
132125
return n;
133126
}
134127

0 commit comments

Comments
 (0)