Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions deps/zlib/contrib/minizip/README.chromium
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,3 @@ Local Modifications:
- Added support for zip64 archives that have extra bytes on front (for example,
large CRX files).
0018-support-prefixed-zip64.patch

- Added stricter parsing for zip64 candidates to avoid an issue where a zip64
could be embedded in a non-zip64 zip.
0019-fix-zip64-in-zip.patch
23 changes: 12 additions & 11 deletions deps/zlib/contrib/minizip/crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ static void init_keys(const char* passwd, unsigned long* pkeys, const z_crc_t* p
#ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED

#define RAND_HEAD_LEN 12
/* "last resort" source for second part of crypt seed pattern */
# ifndef ZCR_SEED2
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
# endif

/* The random header bytes come from the PCG32 generator in skipset.h, which
must be included before this file when INCLUDECRYPTINGCODE_IFCRYPTALLOWED is
defined. */
static unsigned crypthead(const char* passwd, /* password string */
unsigned char* buf, /* where to write header */
int bufSize,
Expand All @@ -92,23 +91,25 @@ static unsigned crypthead(const char* passwd, /* password string */
int t; /* temporary */
int c; /* random byte */
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
static unsigned calls = 0; /* ensure different random header each time */
static int seeded = 0; /* true once gen has been seeded */
static set_rand_t gen; /* random header generator, persists so that
each header is different */

if (bufSize<RAND_HEAD_LEN)
return 0;

/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the
* output of rand() to get less predictability, since rand() is
* often poorly implemented.
/* First generate RAND_HEAD_LEN-2 random bytes. We encrypt the random
* bytes to get less predictability.
*/
if (++calls == 1)
if (!seeded)
{
srand((unsigned)time(NULL) ^ ZCR_SEED2);
set_uniq(&gen, &gen);
seeded = 1;
}
init_keys(passwd, pkeys, pcrc_32_tab);
for (n = 0; n < RAND_HEAD_LEN-2; n++)
{
c = (rand() >> 7) & 0xff;
c = (int)(set_rand(&gen) >> 24);
header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t);
}
/* Encrypt random header (last two bytes is high word of crc) */
Expand Down
2 changes: 1 addition & 1 deletion deps/zlib/contrib/minizip/ioapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#ifndef ZLIBIOAPI64_H
#define ZLIBIOAPI64_H

#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) && (!(defined(__ANDROID_API__) || __ANDROID_API__ >= 24))
#if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) && (!defined(__ANDROID_API__) || __ANDROID_API__ >= 24)

/* Linux needs this to support file operation on files larger then 4+GB */
/* But might need better if/def to select just the platforms that needs them.*/
Expand Down
106 changes: 80 additions & 26 deletions deps/zlib/contrib/minizip/miniunz.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,59 @@ static int makedir(const char *newdir) {
return 1;
}

/* Copy to out a version of the path name that can only be created under the
extraction directory. Both '/' and '\\' are taken as separators. Empty and
"." path components are removed, and a ".." component is removed along with
the component before it, if any. On Windows, drive specifiers at the start
and components of only dots and spaces are also removed. The result is
always a relative path, and is no longer than name. out must have room for
strlen(name) + 1 characters. */
static void safe_path(char* out, const char* name) {
char* start = out;
while (*name != '\0')
{
const char* comp = name;
size_t len;
while (*name != '\0' && *name != '/' && *name != '\\')
name++;
len = (size_t)(name - comp);
#ifdef _WIN32
while (out == start && len >= 2 && comp[1] == ':')
{
comp += 2; /* remove drive specifiers, e.g. "C:" */
len -= 2;
}
{
/* Windows drops trailing dots and spaces from a name, so remove
any other component made of only those, such as "..." */
size_t i = 0;
while (i < len && (comp[i] == '.' || comp[i] == ' '))
i++;
if (i == len && !(len == 2 && comp[0] == '.' && comp[1] == '.'))
len = 0;
}
#endif
if (len == 2 && comp[0] == '.' && comp[1] == '.')
{
/* remove the previous component and its separator, if any */
if (out > start)
out--;
while (out > start && out[-1] != '/' && out[-1] != '\\')
out--;
}
else if (len != 0 && !(len == 1 && comp[0] == '.'))
{
memcpy(out, comp, len);
out += len;
if (*name != '\0')
*out++ = *name; /* keep the separator */
}
if (*name != '\0')
name++;
}
*out = '\0';
}

static void do_banner(void) {
printf("MiniUnz 1.1, demo of zLib + Unz package written by Gilles Vollant\n");
printf("more info at https://www.winimage.com/zLibDll/unzip.html\n\n");
Expand Down Expand Up @@ -267,7 +320,7 @@ static int do_list(unzFile uf) {
string_method="Defl:N";
else if (iLevel==1)
string_method="Defl:X";
else if ((iLevel==2) || (iLevel==3))
else /* iLevel==2 || iLevel==3 */
string_method="Defl:F"; /* 2:fast , 3 : extra fast*/
}
else
Expand Down Expand Up @@ -305,6 +358,7 @@ static int do_list(unzFile uf) {

static int do_extract_currentfile(unzFile uf, const int* popt_extract_without_path, int* popt_overwrite, const char* password) {
char filename_inzip[65536+1];
char write_name[65536+1];
char* filename_withoutpath;
char* p;
int err=UNZ_OK;
Expand Down Expand Up @@ -339,36 +393,28 @@ static int do_extract_currentfile(unzFile uf, const int* popt_extract_without_pa

if ((*filename_withoutpath)=='\0')
{
if ((*popt_extract_without_path)==0)
safe_path(write_name, filename_inzip);
if (((*popt_extract_without_path)==0) && (write_name[0]!='\0'))
{
printf("creating directory: %s\n",filename_inzip);
mymkdir(filename_inzip);
printf("creating directory: %s\n",write_name);
mymkdir(write_name);
}
}
else
{
const char* write_filename;
const char* write_filename = write_name;
int skip=0;

if ((*popt_extract_without_path)==0)
write_filename = filename_inzip;
safe_path(write_name, filename_inzip);
else
write_filename = filename_withoutpath;

if (write_filename[0]!='\0')
safe_path(write_name, filename_withoutpath);
if (write_name[0]=='\0')
{
const char* relative_check = write_filename;
while (relative_check[1]!='\0')
{
if (relative_check[0]=='.' && relative_check[1]=='.')
write_filename = relative_check;
relative_check++;
}
printf("skipping %s: no name left to extract to\n",filename_inzip);
skip = 1;
}

while (write_filename[0]=='/' || write_filename[0]=='.')
write_filename++;

err = unzOpenCurrentFilePassword(uf,password);
if (err!=UNZ_OK)
{
Expand Down Expand Up @@ -412,14 +458,22 @@ static int do_extract_currentfile(unzFile uf, const int* popt_extract_without_pa
{
fout=FOPEN_FUNC(write_filename,"wb");
/* some zipfile don't contain directory alone before file */
if ((fout==NULL) && ((*popt_extract_without_path)==0) &&
(filename_withoutpath!=(char*)filename_inzip))
if ((fout==NULL) && ((*popt_extract_without_path)==0))
{
char c=*(filename_withoutpath-1);
*(filename_withoutpath-1)='\0';
makedir(write_filename);
*(filename_withoutpath-1)=c;
fout=FOPEN_FUNC(write_filename,"wb");
/* make the directories leading up to the file */
char* sep = NULL;
char* q;
for (q = write_name; *q != '\0'; q++)
if (*q == '/' || *q == '\\')
sep = q;
if (sep != NULL)
{
char c = *sep;
*sep = '\0';
makedir(write_name);
*sep = c;
fout=FOPEN_FUNC(write_filename,"wb");
}
}

if (fout==NULL)
Expand Down
2 changes: 1 addition & 1 deletion deps/zlib/contrib/minizip/mztools.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#define READ_8(adr) ((unsigned char)*(adr))
#define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) )
#define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) )
#define READ_32(adr) ( (uLong)READ_16(adr) | ((uLong)READ_16((adr)+2) << 16) )

#define WRITE_8(buff, n) do { \
*((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \
Expand Down
Loading
Loading