Skip to content

Commit

Permalink
Upgrade to zlib 1.12.3
Browse files Browse the repository at this point in the history
Fix #1
Fix #5
  • Loading branch information
philippeVerney committed Jul 29, 2023
1 parent 365a0dc commit c037f06
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 75 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@

# Minizip 1.1
- This is a copy of the official zlib 1.2.11 "contrib/minizip" folder without test, demo and extra files.
- This is a copy of the official zlib 1.2.13 "contrib/minizip" folder without test, demo and extra files.
- You can find binary versions for windows in the Release tab. If you don't find the version for your windows environment, please just ask for it (create an issue).
- You can build the library quite easily by your own by using the cmake file.
- The license is defined in MiniZip64_info.txt file.

# Build remarks
## Windows
When compiling, you are probably going to face this warning which has no direct consequence as far as I know (it may have consequence if you build minizip on window RT) (See issue #1)

.\iowin32.c(31): warning C4067: unexpected tokens following preprocessor directive - expected a newline

## RHEL
Our RHEL 6 machines have zlib.h version 1.2.3 so zip.c will not compile because the type z_crc_t is undefined. An easy fix, since I don't think you care about encrypting RESQML packages, is to simply compile on Linux with -DNOCRYPT.
RHEL 7 seems to have zlib.h version 1.2.7 which does have the z_crc_t type however. (See issue #2)
19 changes: 10 additions & 9 deletions crypt.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab)
* unpredictable manner on 16-bit systems; not a problem
* with any known compiler so far, though */

(void)pcrc_32_tab;
temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2;
return (int)(((temp * (temp ^ 1)) >> 8) & 0xff);
}
Expand Down Expand Up @@ -77,24 +78,24 @@ static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcr
(update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab)))

#define zencode(pkeys,pcrc_32_tab,c,t) \
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c))
(t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), (Byte)t^(c))

#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 */
# define ZCR_SEED2 3141592654UL /* use PI as default pattern */
# endif

static int crypthead(const char* passwd, /* password string */
unsigned char* buf, /* where to write header */
int bufSize,
unsigned long* pkeys,
const z_crc_t* pcrc_32_tab,
unsigned long crcForCrypting)
static unsigned crypthead(const char* passwd, /* password string */
unsigned char* buf, /* where to write header */
int bufSize,
unsigned long* pkeys,
const z_crc_t* pcrc_32_tab,
unsigned long crcForCrypting)
{
int n; /* index in random header */
unsigned n; /* index in random header */
int t; /* temporary */
int c; /* random byte */
unsigned char header[RAND_HEAD_LEN-2]; /* random header */
Expand Down
18 changes: 14 additions & 4 deletions ioapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream
return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
else
{
uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
uLong tell_uLong = (uLong)(*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
if ((tell_uLong) == MAXU32)
return (ZPOS64_T)-1;
else
Expand Down Expand Up @@ -96,6 +96,7 @@ static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, in
{
FILE* file = NULL;
const char* mode_fopen = NULL;
(void)opaque;
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
mode_fopen = "rb";
else
Expand All @@ -114,6 +115,7 @@ static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename,
{
FILE* file = NULL;
const char* mode_fopen = NULL;
(void)opaque;
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
mode_fopen = "rb";
else
Expand All @@ -132,20 +134,23 @@ static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename,
static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
{
uLong ret;
(void)opaque;
ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
return ret;
}

static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
{
uLong ret;
(void)opaque;
ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
return ret;
}

static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
{
long ret;
(void)opaque;
ret = ftell((FILE *)stream);
return ret;
}
Expand All @@ -154,14 +159,16 @@ static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
{
ZPOS64_T ret;
ret = FTELLO_FUNC((FILE *)stream);
(void)opaque;
ret = (ZPOS64_T)FTELLO_FUNC((FILE *)stream);
return ret;
}

static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
{
int fseek_origin=0;
long ret;
(void)opaque;
switch (origin)
{
case ZLIB_FILEFUNC_SEEK_CUR :
Expand All @@ -176,7 +183,7 @@ static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offs
default: return -1;
}
ret = 0;
if (fseek((FILE *)stream, offset, fseek_origin) != 0)
if (fseek((FILE *)stream, (long)offset, fseek_origin) != 0)
ret = -1;
return ret;
}
Expand All @@ -185,6 +192,7 @@ static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T
{
int fseek_origin=0;
long ret;
(void)opaque;
switch (origin)
{
case ZLIB_FILEFUNC_SEEK_CUR :
Expand All @@ -200,7 +208,7 @@ static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T
}
ret = 0;

if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0)
if(FSEEKO_FUNC((FILE *)stream, (z_off_t)offset, fseek_origin) != 0)
ret = -1;

return ret;
Expand All @@ -210,13 +218,15 @@ static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T
static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
{
int ret;
(void)opaque;
ret = fclose((FILE *)stream);
return ret;
}

static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
{
int ret;
(void)opaque;
ret = ferror((FILE *)stream);
return ret;
}
Expand Down
10 changes: 6 additions & 4 deletions ioapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#define ftello64 ftell
#define fseeko64 fseek
#else
#ifdef __FreeBSD__
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
#define fopen64 fopen
#define ftello64 ftello
#define fseeko64 fseeko
Expand Down Expand Up @@ -91,8 +91,7 @@ typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
typedef uint64_t ZPOS64_T;
#else

/* Maximum unsigned 32-bit value used as placeholder for zip64 */
#define MAXU32 0xffffffff


#if defined(_MSC_VER) || defined(__BORLANDC__)
typedef unsigned __int64 ZPOS64_T;
Expand All @@ -102,7 +101,10 @@ typedef unsigned long long int ZPOS64_T;
#endif
#endif


/* Maximum unsigned 32-bit value used as placeholder for zip64 */
#ifndef MAXU32
#define MAXU32 (0xffffffff)
#endif

#ifdef __cplusplus
extern "C" {
Expand Down
5 changes: 5 additions & 0 deletions iowin32.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@

// see Include/shared/winapifamily.h in the Windows Kit
#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API)))

#if !defined(WINAPI_FAMILY_ONE_PARTITION)
#define WINAPI_FAMILY_ONE_PARTITION(PartitionSet, Partition) ((WINAPI_FAMILY & PartitionSet) == Partition)
#endif

#if WINAPI_FAMILY_ONE_PARTITION(WINAPI_FAMILY, WINAPI_PARTITION_APP)
#define IOWIN32_USING_WINRT_API 1
#endif
Expand Down
35 changes: 20 additions & 15 deletions unzip.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
# define ALLOC(size) (malloc(size))
#endif
#ifndef TRYFREE
# define TRYFREE(p) {if (p) free(p);}
# define TRYFREE(p) { free(p);}
#endif

#define SIZECENTRALDIRITEM (0x2e)
Expand Down Expand Up @@ -455,7 +455,7 @@ local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_f
if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
{
uPosFound = uReadPos+i;
uPosFound = uReadPos+(unsigned)i;
break;
}

Expand Down Expand Up @@ -523,7 +523,7 @@ local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib
if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
{
uPosFound = uReadPos+i;
uPosFound = uReadPos+(unsigned)i;
break;
}

Expand Down Expand Up @@ -853,13 +853,13 @@ local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
{
ZPOS64_T uDate;
uDate = (ZPOS64_T)(ulDosDate>>16);
ptm->tm_mday = (uInt)(uDate&0x1f) ;
ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ;
ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
ptm->tm_mday = (int)(uDate&0x1f) ;
ptm->tm_mon = (int)((((uDate)&0x1E0)/0x20)-1) ;
ptm->tm_year = (int)(((uDate&0x0FE00)/0x0200)+1980) ;

ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800);
ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ;
ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ;
ptm->tm_hour = (int) ((ulDosDate &0xF800)/0x800);
ptm->tm_min = (int) ((ulDosDate&0x7E0)/0x20) ;
ptm->tm_sec = (int) (2*(ulDosDate&0x1f)) ;
}

/*
Expand Down Expand Up @@ -993,7 +993,7 @@ local int unz64local_GetCurrentFileInfoInternal (unzFile file,

if (lSeek!=0)
{
if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
if (ZSEEK64(s->z_filefunc, s->filestream,(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
lSeek=0;
else
err=UNZ_ERRNO;
Expand All @@ -1018,7 +1018,7 @@ local int unz64local_GetCurrentFileInfoInternal (unzFile file,

if (lSeek!=0)
{
if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
if (ZSEEK64(s->z_filefunc, s->filestream,(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
lSeek=0;
else
err=UNZ_ERRNO;
Expand Down Expand Up @@ -1090,7 +1090,7 @@ local int unz64local_GetCurrentFileInfoInternal (unzFile file,

if (lSeek!=0)
{
if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
if (ZSEEK64(s->z_filefunc, s->filestream,(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
lSeek=0;
else
err=UNZ_ERRNO;
Expand Down Expand Up @@ -1566,6 +1566,7 @@ extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
else
{
TRYFREE(pfile_in_zip_read_info->read_buffer);
TRYFREE(pfile_in_zip_read_info);
return err;
}
Expand All @@ -1586,6 +1587,7 @@ extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
else
{
TRYFREE(pfile_in_zip_read_info->read_buffer);
TRYFREE(pfile_in_zip_read_info);
return err;
}
Expand Down Expand Up @@ -1767,7 +1769,7 @@ extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)

if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
(pfile_in_zip_read_info->rest_read_compressed == 0))
return (iRead==0) ? UNZ_EOF : iRead;
return (iRead==0) ? UNZ_EOF : (int)iRead;

if (pfile_in_zip_read_info->stream.avail_out <
pfile_in_zip_read_info->stream.avail_in)
Expand Down Expand Up @@ -1857,6 +1859,9 @@ extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
err = Z_DATA_ERROR;

uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
/* Detect overflow, because z_stream.total_out is uLong (32 bits) */
if (uTotalOutAfter<uTotalOutBefore)
uTotalOutAfter += 1LL << 32; /* Add maximum value of uLong + 1 */
uOutThis = uTotalOutAfter-uTotalOutBefore;

pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
Expand All @@ -1871,14 +1876,14 @@ extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);

if (err==Z_STREAM_END)
return (iRead==0) ? UNZ_EOF : iRead;
return (iRead==0) ? UNZ_EOF : (int)iRead;
if (err!=Z_OK)
break;
}
}

if (err==Z_OK)
return iRead;
return (int)iRead;
return err;
}

Expand Down
12 changes: 6 additions & 6 deletions unzip.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ typedef voidp unzFile;
/* tm_unz contain date/time info */
typedef struct tm_unz_s
{
uInt tm_sec; /* seconds after the minute - [0,59] */
uInt tm_min; /* minutes after the hour - [0,59] */
uInt tm_hour; /* hours since midnight - [0,23] */
uInt tm_mday; /* day of the month - [1,31] */
uInt tm_mon; /* months since January - [0,11] */
uInt tm_year; /* years - [1980..2044] */
int tm_sec; /* seconds after the minute - [0,59] */
int tm_min; /* minutes after the hour - [0,59] */
int tm_hour; /* hours since midnight - [0,23] */
int tm_mday; /* day of the month - [1,31] */
int tm_mon; /* months since January - [0,11] */
int tm_year; /* years - [1980..2044] */
} tm_unz;

/* unz_global_info structure contain global data about the ZIPfile
Expand Down
Loading

0 comments on commit c037f06

Please sign in to comment.