summaryrefslogtreecommitdiff
path: root/zlib/contrib/minizip
diff options
context:
space:
mode:
Diffstat (limited to 'zlib/contrib/minizip')
-rw-r--r--zlib/contrib/minizip/ChangeLogUnzip12
-rw-r--r--zlib/contrib/minizip/miniunz.c41
-rw-r--r--zlib/contrib/minizip/minizip.c37
-rw-r--r--zlib/contrib/minizip/unzip.c66
-rw-r--r--zlib/contrib/minizip/unzip.h18
-rw-r--r--zlib/contrib/minizip/zip.c71
-rw-r--r--zlib/contrib/minizip/zip.h8
7 files changed, 215 insertions, 38 deletions
diff --git a/zlib/contrib/minizip/ChangeLogUnzip b/zlib/contrib/minizip/ChangeLogUnzip
index d7d4b6ba5847..50ca6a9e0f32 100644
--- a/zlib/contrib/minizip/ChangeLogUnzip
+++ b/zlib/contrib/minizip/ChangeLogUnzip
@@ -1,3 +1,15 @@
+Change in 1.01e (12 feb 05)
+- Fix in zipOpen2 for globalcomment (Rolf Kalbermatter)
+- Fix possible memory leak in unzip.c (Zoran Stevanovic)
+
+Change in 1.01b (20 may 04)
+- Integrate patch from Debian package (submited by Mark Brown)
+- Add tools mztools from Xavier Roche
+
+Change in 1.01 (8 may 04)
+- fix buffer overrun risk in unzip.c (Xavier Roche)
+- fix a minor buffer insecurity in minizip.c (Mike Whittaker)
+
Change in 1.00: (10 sept 03)
- rename to 1.00
- cosmetic code change
diff --git a/zlib/contrib/minizip/miniunz.c b/zlib/contrib/minizip/miniunz.c
index c8cf81e3be37..f599938884eb 100644
--- a/zlib/contrib/minizip/miniunz.c
+++ b/zlib/contrib/minizip/miniunz.c
@@ -1,3 +1,11 @@
+/*
+ miniunz.c
+ Version 1.01e, February 12th, 2005
+
+ Copyright (C) 1998-2005 Gilles Vollant
+*/
+
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -27,7 +35,7 @@
mini unzip, demo of unzip package
usage :
- Usage : miniunz [-exvlo] file.zip [file_to_extract]
+ Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir]
list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT
if it exists
@@ -140,17 +148,18 @@ int makedir (newdir)
void do_banner()
{
- printf("MiniUnz 1.00, demo of zLib + Unz package written by Gilles Vollant\n");
+ printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n");
printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
}
void do_help()
{
- printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.]\n\n" \
+ printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \
" -e Extract without pathname (junk paths)\n" \
" -x Extract with pathname\n" \
" -v list files\n" \
" -l list files\n" \
+ " -d directory to extract into\n" \
" -o overwrite files without prompting\n" \
" -p extract crypted file using password\n\n");
}
@@ -304,8 +313,14 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password)
do
{
char answer[128];
- printf("The file %s exist. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
- scanf("%1s",answer);
+ int ret;
+
+ printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename);
+ ret = scanf("%1s",answer);
+ if (ret != 1)
+ {
+ exit(EXIT_FAILURE);
+ }
rep = answer[0] ;
if ((rep>='a') && (rep<='z'))
rep -= 0x20;
@@ -459,6 +474,8 @@ int main(argc,argv)
int opt_do_extract=1;
int opt_do_extract_withoutpath=0;
int opt_overwrite=0;
+ int opt_extractdir=0;
+ const char *dirname=NULL;
unzFile uf=NULL;
do_banner();
@@ -488,6 +505,12 @@ int main(argc,argv)
opt_do_extract = opt_do_extract_withoutpath = 1;
if ((c=='o') || (c=='O'))
opt_overwrite=1;
+ if ((c=='d') || (c=='D'))
+ {
+ opt_extractdir=1;
+ dirname=argv[i+1];
+ }
+
if (((c=='p') || (c=='P')) && (i+1<argc))
{
password=argv[i+1];
@@ -499,7 +522,7 @@ int main(argc,argv)
{
if (zipfilename == NULL)
zipfilename = argv[i];
- else if (filename_to_extract==NULL)
+ else if ((filename_to_extract==NULL) && (!opt_extractdir))
filename_to_extract = argv[i] ;
}
}
@@ -544,6 +567,12 @@ int main(argc,argv)
return do_list(uf);
else if (opt_do_extract==1)
{
+ if (opt_extractdir && chdir(dirname))
+ {
+ printf("Error changing into %s, aborting\n", dirname);
+ exit(-1);
+ }
+
if (filename_to_extract == NULL)
return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password);
else
diff --git a/zlib/contrib/minizip/minizip.c b/zlib/contrib/minizip/minizip.c
index 5746f5cff8d4..f2dfecd8b121 100644
--- a/zlib/contrib/minizip/minizip.c
+++ b/zlib/contrib/minizip/minizip.c
@@ -1,3 +1,10 @@
+/*
+ minizip.c
+ Version 1.01e, February 12th, 2005
+
+ Copyright (C) 1998-2005 Gilles Vollant
+*/
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -53,8 +60,8 @@ uLong filetime(f, tmzip, dt)
#else
#ifdef unix
uLong filetime(f, tmzip, dt)
- char *f; /* name of file to get info on */
- tm_zip *tmzip; /* return value: access, modific. and creation times */
+ char *f; /* name of file to get info on */
+ tm_zip *tmzip; /* return value: access, modific. and creation times */
uLong *dt; /* dostime */
{
int ret=0;
@@ -66,6 +73,8 @@ uLong filetime(f, tmzip, dt)
{
char name[MAXFILENAME+1];
int len = strlen(f);
+ if (len > MAXFILENAME)
+ len = MAXFILENAME;
strncpy(name, f,MAXFILENAME-1);
/* strncpy doesnt append the trailing NULL, of the string is too long. */
@@ -120,7 +129,7 @@ int check_exist_file(filename)
void do_banner()
{
- printf("MiniZip 1.00, demo of zLib + Zip package written by Gilles Vollant\n");
+ printf("MiniZip 1.01b, demo of zLib + Zip package written by Gilles Vollant\n");
printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
}
@@ -269,8 +278,13 @@ int main(argc,argv)
do
{
char answer[128];
- printf("The file %s exist. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
- scanf("%1s",answer);
+ int ret;
+ printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try);
+ ret = scanf("%1s",answer);
+ if (ret != 1)
+ {
+ exit(EXIT_FAILURE);
+ }
rep = answer[0] ;
if ((rep>='a') && (rep<='z'))
rep -= 0x20;
@@ -305,7 +319,12 @@ int main(argc,argv)
for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++)
{
- if (((*(argv[i]))!='-') && ((*(argv[i]))!='/'))
+ if (!((((*(argv[i]))=='-') || ((*(argv[i]))=='/')) &&
+ ((argv[i][1]=='o') || (argv[i][1]=='O') ||
+ (argv[i][1]=='a') || (argv[i][1]=='A') ||
+ (argv[i][1]=='p') || (argv[i][1]=='P') ||
+ ((argv[i][1]>='0') || (argv[i][1]<='9'))) &&
+ (strlen(argv[i]) == 2)))
{
FILE * fin;
int size_read;
@@ -390,7 +409,11 @@ int main(argc,argv)
errclose = zipClose(zf,NULL);
if (errclose != ZIP_OK)
printf("error in closing %s\n",filename_try);
- }
+ }
+ else
+ {
+ do_help();
+ }
free(buf);
return 0;
diff --git a/zlib/contrib/minizip/unzip.c b/zlib/contrib/minizip/unzip.c
index f08f624f00f2..9ad4766d8db3 100644
--- a/zlib/contrib/minizip/unzip.c
+++ b/zlib/contrib/minizip/unzip.c
@@ -1,7 +1,7 @@
/* unzip.c -- IO for uncompress .zip files using zlib
- Version 1.00, September 10th, 2003
+ Version 1.01e, February 12th, 2005
- Copyright (C) 1998-2003 Gilles Vollant
+ Copyright (C) 1998-2005 Gilles Vollant
Read unzip.h for more info
*/
@@ -88,7 +88,7 @@ woven in by Terry Thorsen 1/2003.
const char unz_copyright[] =
- " unzip 1.00 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll";
+ " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
/* unz_file_info_interntal contain internal info about a file in zipfile*/
typedef struct unz_file_info_internal_s
@@ -798,7 +798,8 @@ extern int ZEXPORT unzGoToNextFile (file)
s=(unz_s*)file;
if (!s->current_file_ok)
return UNZ_END_OF_LIST_OF_FILE;
- if (s->num_file+1==s->gi.number_entry)
+ if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */
+ if (s->num_file+1==s->gi.number_entry)
return UNZ_END_OF_LIST_OF_FILE;
s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
@@ -1136,7 +1137,10 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
if (err == Z_OK)
pfile_in_zip_read_info->stream_initialised=1;
else
+ {
+ TRYFREE(pfile_in_zip_read_info);
return err;
+ }
/* windowBits is passed < 0 to tell that there is no zlib header.
* Note that in this case inflate *requires* an extra "dummy" byte
* after the compressed stream in order to complete decompression and
@@ -1244,9 +1248,17 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
pfile_in_zip_read_info->stream.avail_out = (uInt)len;
- if (len>pfile_in_zip_read_info->rest_read_uncompressed)
+ if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
+ (!(pfile_in_zip_read_info->raw)))
+ pfile_in_zip_read_info->stream.avail_out =
+ (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
+
+ if ((len>pfile_in_zip_read_info->rest_read_compressed+
+ pfile_in_zip_read_info->stream.avail_in) &&
+ (pfile_in_zip_read_info->raw))
pfile_in_zip_read_info->stream.avail_out =
- (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
+ (uInt)pfile_in_zip_read_info->rest_read_compressed+
+ pfile_in_zip_read_info->stream.avail_in;
while (pfile_in_zip_read_info->stream.avail_out>0)
{
@@ -1339,6 +1351,9 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
*/
err=inflate(&pfile_in_zip_read_info->stream,flush);
+ if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
+ err = Z_DATA_ERROR;
+
uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
uOutThis = uTotalOutAfter-uTotalOutBefore;
@@ -1461,7 +1476,7 @@ extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
if (ZREAD(pfile_in_zip_read_info->z_filefunc,
pfile_in_zip_read_info->filestream,
- buf,size_to_read)!=size_to_read)
+ buf,read_now)!=read_now)
return UNZ_ERRNO;
return (int)read_now;
@@ -1544,3 +1559,40 @@ extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
*(szComment+s->gi.size_comment)='\0';
return (int)uReadThis;
}
+
+/* Additions by RX '2004 */
+extern uLong ZEXPORT unzGetOffset (file)
+ unzFile file;
+{
+ unz_s* s;
+
+ if (file==NULL)
+ return UNZ_PARAMERROR;
+ s=(unz_s*)file;
+ if (!s->current_file_ok)
+ return 0;
+ if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
+ if (s->num_file==s->gi.number_entry)
+ return 0;
+ return s->pos_in_central_dir;
+}
+
+extern int ZEXPORT unzSetOffset (file, pos)
+ unzFile file;
+ uLong pos;
+{
+ unz_s* s;
+ int err;
+
+ if (file==NULL)
+ return UNZ_PARAMERROR;
+ s=(unz_s*)file;
+
+ s->pos_in_central_dir = pos;
+ s->num_file = s->gi.number_entry; /* hack */
+ err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info,
+ &s->cur_file_info_internal,
+ NULL,0,NULL,0,NULL,0);
+ s->current_file_ok = (err == UNZ_OK);
+ return err;
+}
diff --git a/zlib/contrib/minizip/unzip.h b/zlib/contrib/minizip/unzip.h
index 4e50979d8eab..b247937c8078 100644
--- a/zlib/contrib/minizip/unzip.h
+++ b/zlib/contrib/minizip/unzip.h
@@ -1,11 +1,13 @@
/* unzip.h -- IO for uncompress .zip files using zlib
- Version 1.00, September 10th, 2003
+ Version 1.01e, February 12th, 2005
- Copyright (C) 1998-2003 Gilles Vollant
+ Copyright (C) 1998-2005 Gilles Vollant
This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
- Encryption and multi volume ZipFile (span) are not supported.
+
+ Multi volume ZipFile (span) are not supported.
+ Encryption compatible with pkzip 2.04g only supported
Old compressions used by old PKZip 1.x are not supported
@@ -335,6 +337,16 @@ extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
the error code
*/
+/***************************************************************************/
+
+/* Get the current file offset */
+extern uLong ZEXPORT unzGetOffset (unzFile file);
+
+/* Set the current file offset */
+extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
+
+
+
#ifdef __cplusplus
}
#endif
diff --git a/zlib/contrib/minizip/zip.c b/zlib/contrib/minizip/zip.c
index 1a713e508420..7fbe0027437e 100644
--- a/zlib/contrib/minizip/zip.c
+++ b/zlib/contrib/minizip/zip.c
@@ -1,7 +1,10 @@
/* zip.c -- IO on .zip files using zlib
- Version 1.00, September 10th, 2003
+ Version 1.01e, February 12th, 2005
- Copyright (C) 1998-2003 Gilles Vollant
+ 27 Dec 2004 Rolf Kalbermatter
+ Modification to zipOpen2 to support globalComment retrieval.
+
+ Copyright (C) 1998-2005 Gilles Vollant
Read zip.h for more info
*/
@@ -77,7 +80,7 @@
#endif
#endif
const char zip_copyright[] =
- " zip 1.00 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll";
+ " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
#define SIZEDATA_INDATABLOCK (4096-(4*4))
@@ -143,6 +146,9 @@ typedef struct
uLong begin_pos; /* position of the beginning of the zipfile */
uLong add_position_when_writting_offset;
uLong number_entry;
+#ifndef NO_ADDFILEINEXISTINGZIP
+ char *globalcomment;
+#endif
} zip_internal;
@@ -265,10 +271,19 @@ local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte)
{
unsigned char buf[4];
int n;
- for (n = 0; n < nbByte; n++) {
+ for (n = 0; n < nbByte; n++)
+ {
buf[n] = (unsigned char)(x & 0xff);
x >>= 8;
}
+ if (x != 0)
+ { /* data overflow - hack for ZIP64 (X Roche) */
+ for (n = 0; n < nbByte; n++)
+ {
+ buf[n] = 0xff;
+ }
+ }
+
if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
return ZIP_ERRNO;
else
@@ -287,7 +302,16 @@ local void ziplocal_putValue_inmemory (dest, x, nbByte)
buf[n] = (unsigned char)(x & 0xff);
x >>= 8;
}
+
+ if (x != 0)
+ { /* data overflow - hack for ZIP64 */
+ for (n = 0; n < nbByte; n++)
+ {
+ buf[n] = 0xff;
+ }
+ }
}
+
/****************************************************************************/
@@ -514,6 +538,7 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc
/* now we add file in a zipfile */
# ifndef NO_ADDFILEINEXISTINGZIP
+ ziinit.globalcomment = NULL;
if (append == APPEND_STATUS_ADDINZIP)
{
uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
@@ -574,7 +599,7 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc
if (ziplocal_getLong(&ziinit.z_filefunc, ziinit.filestream,&offset_central_dir)!=ZIP_OK)
err=ZIP_ERRNO;
- /* zipfile comment length */
+ /* zipfile global comment length */
if (ziplocal_getShort(&ziinit.z_filefunc, ziinit.filestream,&size_comment)!=ZIP_OK)
err=ZIP_ERRNO;
@@ -588,9 +613,19 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc
return NULL;
}
+ if (size_comment>0)
+ {
+ ziinit.globalcomment = ALLOC(size_comment+1);
+ if (ziinit.globalcomment)
+ {
+ size_comment = ZREAD(ziinit.z_filefunc, ziinit.filestream,ziinit.globalcomment,size_comment);
+ ziinit.globalcomment[size_comment]=0;
+ }
+ }
+
byte_before_the_zipfile = central_pos -
(offset_central_dir+size_central_dir);
- ziinit.add_position_when_writting_offset = byte_before_the_zipfile ;
+ ziinit.add_position_when_writting_offset = byte_before_the_zipfile;
{
uLong size_central_dir_to_read = size_central_dir;
@@ -623,10 +658,18 @@ extern zipFile ZEXPORT zipOpen2 (pathname, append, globalcomment, pzlib_filefunc
offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
err=ZIP_ERRNO;
}
+
+ if (globalcomment)
+ {
+ *globalcomment = ziinit.globalcomment;
+ }
# endif /* !NO_ADDFILEINEXISTINGZIP*/
if (err != ZIP_OK)
{
+# ifndef NO_ADDFILEINEXISTINGZIP
+ TRYFREE(ziinit.globalcomment);
+# endif /* !NO_ADDFILEINEXISTINGZIP*/
TRYFREE(zi);
return NULL;
}
@@ -699,9 +742,9 @@ extern int ZEXPORT zipOpenNewFileInZip3 (file, filename, zipfi,
if (comment==NULL)
size_comment = 0;
else
- size_comment = strlen(comment);
+ size_comment = (uInt)strlen(comment);
- size_filename = strlen(filename);
+ size_filename = (uInt)strlen(filename);
if (zipfi == NULL)
zi->ci.dosDate = 0;
@@ -1094,7 +1137,7 @@ extern int ZEXPORT zipClose (file, global_comment)
zip_internal* zi;
int err = 0;
uLong size_centraldir = 0;
- uLong centraldir_pos_inzip ;
+ uLong centraldir_pos_inzip;
uInt size_global_comment;
if (file == NULL)
return ZIP_PARAMERROR;
@@ -1105,11 +1148,14 @@ extern int ZEXPORT zipClose (file, global_comment)
err = zipCloseFileInZip (file);
}
+#ifndef NO_ADDFILEINEXISTINGZIP
+ if (global_comment==NULL)
+ global_comment = zi->globalcomment;
+#endif
if (global_comment==NULL)
size_global_comment = 0;
else
- size_global_comment = strlen(global_comment);
-
+ size_global_comment = (uInt)strlen(global_comment);
centraldir_pos_inzip = ZTELL(zi->z_filefunc,zi->filestream);
if (err==ZIP_OK)
@@ -1164,6 +1210,9 @@ extern int ZEXPORT zipClose (file, global_comment)
if (err == ZIP_OK)
err = ZIP_ERRNO;
+#ifndef NO_ADDFILEINEXISTINGZIP
+ TRYFREE(zi->globalcomment);
+#endif
TRYFREE(zi);
return err;
diff --git a/zlib/contrib/minizip/zip.h b/zlib/contrib/minizip/zip.h
index c37ea21872ca..acacce83b9b5 100644
--- a/zlib/contrib/minizip/zip.h
+++ b/zlib/contrib/minizip/zip.h
@@ -1,11 +1,12 @@
/* zip.h -- IO for compress .zip files using zlib
- Version 1.00, September 10th, 2003
+ Version 1.01e, February 12th, 2005
- Copyright (C) 1998-2003 Gilles Vollant
+ Copyright (C) 1998-2005 Gilles Vollant
This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
WinZip, InfoZip tools and compatible.
- Encryption and multi volume ZipFile (span) are not supported.
+ Multi volume ZipFile (span) are not supported.
+ Encryption compatible with pkzip 2.04g only supported
Old compressions used by old PKZip 1.x are not supported
For uncompress .zip file, look at unzip.h
@@ -212,7 +213,6 @@ extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
Close the current file in the zipfile
*/
-
extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
uLong uncompressed_size,
uLong crc32));