Skip to content

Commit 76ce14e

Browse files
committed
Update minizip
1 parent ee05ac9 commit 76ce14e

File tree

11 files changed

+3205
-1240
lines changed

11 files changed

+3205
-1240
lines changed

vendor/zip/crypt.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,21 @@
3232
/***********************************************************************
3333
* Return the next byte in the pseudo-random sequence
3434
*/
35-
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
35+
static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab)
3636
{
3737
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
3838
* unpredictable manner on 16-bit systems; not a problem
3939
* with any known compiler so far, though */
4040

41+
(void)pcrc_32_tab;
4142
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
4243
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
4344
}
4445

4546
/***********************************************************************
4647
* Update the encryption keys with the next byte of plain text
4748
*/
48-
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
49+
static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c)
4950
{
5051
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
5152
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
@@ -62,7 +63,7 @@ static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int
6263
* Initialize the encryption keys and the random header according to
6364
* the given password.
6465
*/
65-
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
66+
static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcrc_32_tab)
6667
{
6768
*(pkeys+0) = 305419896L;
6869
*(pkeys+1) = 591751049L;
@@ -77,25 +78,24 @@ static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned lon
7778
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))
7879

7980
#define zencode(pkeys,pcrc_32_tab,c,t) \
80-
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
81+
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), (Byte)t^(c))
8182

8283
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED
8384

8485
#define RAND_HEAD_LEN 12
8586
/* "last resort" source for second part of crypt seed pattern */
8687
# ifndef ZCR_SEED2
87-
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
88+
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
8889
# endif
8990

90-
static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
91-
const char *passwd; /* password string */
92-
unsigned char *buf; /* where to write header */
93-
int bufSize;
94-
unsigned long* pkeys;
95-
const unsigned long* pcrc_32_tab;
96-
unsigned long crcForCrypting;
91+
static unsigned crypthead(const char* passwd, /* password string */
92+
unsigned char* buf, /* where to write header */
93+
int bufSize,
94+
unsigned long* pkeys,
95+
const z_crc_t* pcrc_32_tab,
96+
unsigned long crcForCrypting)
9797
{
98-
int n; /* index in random header */
98+
unsigned n; /* index in random header */
9999
int t; /* temporary */
100100
int c; /* random byte */
101101
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
@@ -124,8 +124,8 @@ static int crypthead(passwd, buf, bufSize, pkeys, pcrc_32_tab, crcForCrypting)
124124
{
125125
buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t);
126126
}
127-
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
128-
buf[n++] = zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
127+
buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t);
128+
buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t);
129129
return n;
130130
}
131131

vendor/zip/ioapi.c

Lines changed: 159 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,102 @@
1-
/* ioapi.c -- IO base function header for compress/uncompress .zip
2-
files using zlib + zip or unzip API
1+
/* ioapi.h -- IO base function header for compress/uncompress .zip
2+
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
33
4-
Version 1.01e, February 12th, 2005
5-
6-
Copyright (C) 1998-2005 Gilles Vollant
7-
*/
8-
9-
#include <stdio.h>
10-
#include <stdlib.h>
11-
#include <string.h>
12-
13-
#include "zlib.h"
14-
#include "ioapi.h"
4+
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
155
6+
Modifications for Zip64 support
7+
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
168
9+
For more info read MiniZip_info.txt
1710
18-
/* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
11+
*/
1912

20-
#ifndef SEEK_CUR
21-
#define SEEK_CUR 1
13+
#if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS)))
14+
#define _CRT_SECURE_NO_WARNINGS
2215
#endif
2316

24-
#ifndef SEEK_END
25-
#define SEEK_END 2
17+
#if defined(__APPLE__) || defined(IOAPI_NO_64)
18+
// In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
19+
#define FOPEN_FUNC(filename, mode) fopen(filename, mode)
20+
#define FTELLO_FUNC(stream) ftello(stream)
21+
#define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
22+
#else
23+
#define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
24+
#define FTELLO_FUNC(stream) ftello64(stream)
25+
#define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
2626
#endif
2727

28-
#ifndef SEEK_SET
29-
#define SEEK_SET 0
30-
#endif
3128

32-
voidpf ZCALLBACK fopen_file_func OF((
33-
voidpf opaque,
34-
const char* filename,
35-
int mode));
29+
#include "ioapi.h"
3630

37-
uLong ZCALLBACK fread_file_func OF((
38-
voidpf opaque,
39-
voidpf stream,
40-
void* buf,
41-
uLong size));
31+
voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
32+
{
33+
if (pfilefunc->zfile_func64.zopen64_file != NULL)
34+
return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
35+
else
36+
{
37+
return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
38+
}
39+
}
4240

43-
uLong ZCALLBACK fwrite_file_func OF((
44-
voidpf opaque,
45-
voidpf stream,
46-
const void* buf,
47-
uLong size));
41+
long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
42+
{
43+
if (pfilefunc->zfile_func64.zseek64_file != NULL)
44+
return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
45+
else
46+
{
47+
uLong offsetTruncated = (uLong)offset;
48+
if (offsetTruncated != offset)
49+
return -1;
50+
else
51+
return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
52+
}
53+
}
4854

49-
long ZCALLBACK ftell_file_func OF((
50-
voidpf opaque,
51-
voidpf stream));
55+
ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
56+
{
57+
if (pfilefunc->zfile_func64.zseek64_file != NULL)
58+
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
59+
else
60+
{
61+
uLong tell_uLong = (uLong)(*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
62+
if ((tell_uLong) == MAXU32)
63+
return (ZPOS64_T)-1;
64+
else
65+
return tell_uLong;
66+
}
67+
}
5268

53-
long ZCALLBACK fseek_file_func OF((
54-
voidpf opaque,
55-
voidpf stream,
56-
uLong offset,
57-
int origin));
69+
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)
70+
{
71+
p_filefunc64_32->zfile_func64.zopen64_file = NULL;
72+
p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
73+
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
74+
p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
75+
p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
76+
p_filefunc64_32->zfile_func64.ztell64_file = NULL;
77+
p_filefunc64_32->zfile_func64.zseek64_file = NULL;
78+
p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
79+
p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
80+
p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
81+
p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
82+
p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
83+
}
5884

59-
int ZCALLBACK fclose_file_func OF((
60-
voidpf opaque,
61-
voidpf stream));
6285

63-
int ZCALLBACK ferror_file_func OF((
64-
voidpf opaque,
65-
voidpf stream));
6686

87+
static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
88+
static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
89+
static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
90+
static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
91+
static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
92+
static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
93+
static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
6794

68-
voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
69-
voidpf opaque;
70-
const char* filename;
71-
int mode;
95+
static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
7296
{
7397
FILE* file = NULL;
7498
const char* mode_fopen = NULL;
99+
(void)opaque;
75100
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
76101
mode_fopen = "rb";
77102
else
@@ -86,47 +111,64 @@ voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
86111
return file;
87112
}
88113

114+
static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
115+
{
116+
FILE* file = NULL;
117+
const char* mode_fopen = NULL;
118+
(void)opaque;
119+
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
120+
mode_fopen = "rb";
121+
else
122+
if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
123+
mode_fopen = "r+b";
124+
else
125+
if (mode & ZLIB_FILEFUNC_MODE_CREATE)
126+
mode_fopen = "wb";
127+
128+
if ((filename!=NULL) && (mode_fopen != NULL))
129+
file = FOPEN_FUNC((const char*)filename, mode_fopen);
130+
return file;
131+
}
132+
89133

90-
uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
91-
voidpf opaque;
92-
voidpf stream;
93-
void* buf;
94-
uLong size;
134+
static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
95135
{
96136
uLong ret;
137+
(void)opaque;
97138
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
98139
return ret;
99140
}
100141

101-
102-
uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
103-
voidpf opaque;
104-
voidpf stream;
105-
const void* buf;
106-
uLong size;
142+
static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
107143
{
108144
uLong ret;
145+
(void)opaque;
109146
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
110147
return ret;
111148
}
112149

113-
long ZCALLBACK ftell_file_func (opaque, stream)
114-
voidpf opaque;
115-
voidpf stream;
150+
static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
116151
{
117152
long ret;
153+
(void)opaque;
118154
ret = ftell((FILE *)stream);
119155
return ret;
120156
}
121157

122-
long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
123-
voidpf opaque;
124-
voidpf stream;
125-
uLong offset;
126-
int origin;
158+
159+
static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
160+
{
161+
ZPOS64_T ret;
162+
(void)opaque;
163+
ret = (ZPOS64_T)FTELLO_FUNC((FILE *)stream);
164+
return ret;
165+
}
166+
167+
static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
127168
{
128169
int fseek_origin=0;
129170
long ret;
171+
(void)opaque;
130172
switch (origin)
131173
{
132174
case ZLIB_FILEFUNC_SEEK_CUR :
@@ -141,24 +183,50 @@ long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
141183
default: return -1;
142184
}
143185
ret = 0;
144-
fseek((FILE *)stream, offset, fseek_origin);
186+
if (fseek((FILE *)stream, (long)offset, fseek_origin) != 0)
187+
ret = -1;
145188
return ret;
146189
}
147190

148-
int ZCALLBACK fclose_file_func (opaque, stream)
149-
voidpf opaque;
150-
voidpf stream;
191+
static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
192+
{
193+
int fseek_origin=0;
194+
long ret;
195+
(void)opaque;
196+
switch (origin)
197+
{
198+
case ZLIB_FILEFUNC_SEEK_CUR :
199+
fseek_origin = SEEK_CUR;
200+
break;
201+
case ZLIB_FILEFUNC_SEEK_END :
202+
fseek_origin = SEEK_END;
203+
break;
204+
case ZLIB_FILEFUNC_SEEK_SET :
205+
fseek_origin = SEEK_SET;
206+
break;
207+
default: return -1;
208+
}
209+
ret = 0;
210+
211+
if(FSEEKO_FUNC((FILE *)stream, (z_off_t)offset, fseek_origin) != 0)
212+
ret = -1;
213+
214+
return ret;
215+
}
216+
217+
218+
static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
151219
{
152220
int ret;
221+
(void)opaque;
153222
ret = fclose((FILE *)stream);
154223
return ret;
155224
}
156225

157-
int ZCALLBACK ferror_file_func (opaque, stream)
158-
voidpf opaque;
159-
voidpf stream;
226+
static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
160227
{
161228
int ret;
229+
(void)opaque;
162230
ret = ferror((FILE *)stream);
163231
return ret;
164232
}
@@ -175,3 +243,15 @@ void fill_fopen_filefunc (pzlib_filefunc_def)
175243
pzlib_filefunc_def->zerror_file = ferror_file_func;
176244
pzlib_filefunc_def->opaque = NULL;
177245
}
246+
247+
void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
248+
{
249+
pzlib_filefunc_def->zopen64_file = fopen64_file_func;
250+
pzlib_filefunc_def->zread_file = fread_file_func;
251+
pzlib_filefunc_def->zwrite_file = fwrite_file_func;
252+
pzlib_filefunc_def->ztell64_file = ftell64_file_func;
253+
pzlib_filefunc_def->zseek64_file = fseek64_file_func;
254+
pzlib_filefunc_def->zclose_file = fclose_file_func;
255+
pzlib_filefunc_def->zerror_file = ferror_file_func;
256+
pzlib_filefunc_def->opaque = NULL;
257+
}

0 commit comments

Comments
 (0)