diff options
Diffstat (limited to 'contrib/minizip')
-rw-r--r-- | contrib/minizip/ChangeLogUnzip | 8 | ||||
-rw-r--r-- | contrib/minizip/crypt.h | 4 | ||||
-rw-r--r-- | contrib/minizip/ioapi.c | 4 | ||||
-rw-r--r-- | contrib/minizip/ioapi.h | 4 | ||||
-rw-r--r-- | contrib/minizip/iowin32.c | 4 | ||||
-rw-r--r-- | contrib/minizip/iowin32.h | 4 | ||||
-rw-r--r-- | contrib/minizip/miniunz.c | 41 | ||||
-rw-r--r-- | contrib/minizip/minizip.c | 37 | ||||
-rw-r--r-- | contrib/minizip/mztools.c | 281 | ||||
-rw-r--r-- | contrib/minizip/mztools.h | 31 | ||||
-rw-r--r-- | contrib/minizip/unzip.c | 61 | ||||
-rw-r--r-- | contrib/minizip/unzip.h | 14 | ||||
-rw-r--r-- | contrib/minizip/zip.c | 26 | ||||
-rw-r--r-- | contrib/minizip/zip.h | 5 |
14 files changed, 485 insertions, 39 deletions
diff --git a/contrib/minizip/ChangeLogUnzip b/contrib/minizip/ChangeLogUnzip index d7d4b6b..4be4d16 100644 --- a/contrib/minizip/ChangeLogUnzip +++ b/contrib/minizip/ChangeLogUnzip | |||
@@ -1,3 +1,11 @@ | |||
1 | Change in 1.01b (20 may 04) | ||
2 | - Integrate patch from Debian package (submited by Mark Brown) | ||
3 | - Add tools mztools from Xavier Roche | ||
4 | |||
5 | Change in 1.01 (8 may 04) | ||
6 | - fix buffer overrun risk in unzip.c (Xavier Roche) | ||
7 | - fix a minor buffer insecurity in minizip.c (Mike Whittaker) | ||
8 | |||
1 | Change in 1.00: (10 sept 03) | 9 | Change in 1.00: (10 sept 03) |
2 | - rename to 1.00 | 10 | - rename to 1.00 |
3 | - cosmetic code change | 11 | - cosmetic code change |
diff --git a/contrib/minizip/crypt.h b/contrib/minizip/crypt.h index 9c7a89c..7f8a634 100644 --- a/contrib/minizip/crypt.h +++ b/contrib/minizip/crypt.h | |||
@@ -1,9 +1,9 @@ | |||
1 | /* crypt.h -- base code for crypt/uncrypt ZIPfile | 1 | /* crypt.h -- base code for crypt/uncrypt ZIPfile |
2 | 2 | ||
3 | 3 | ||
4 | Version 1.00, September 10th, 2003 | 4 | Version 1.01, May 8th, 2004 |
5 | 5 | ||
6 | Copyright (C) 1998-2003 Gilles Vollant | 6 | Copyright (C) 1998-2004 Gilles Vollant |
7 | 7 | ||
8 | This code is a modified version of crypting code in Infozip distribution | 8 | This code is a modified version of crypting code in Infozip distribution |
9 | 9 | ||
diff --git a/contrib/minizip/ioapi.c b/contrib/minizip/ioapi.c index 80443b7..6ddfd36 100644 --- a/contrib/minizip/ioapi.c +++ b/contrib/minizip/ioapi.c | |||
@@ -1,9 +1,9 @@ | |||
1 | /* ioapi.c -- IO base function header for compress/uncompress .zip | 1 | /* ioapi.c -- IO base function header for compress/uncompress .zip |
2 | files using zlib + zip or unzip API | 2 | files using zlib + zip or unzip API |
3 | 3 | ||
4 | Version 1.00, September 10th, 2003 | 4 | Version 1.01, May 8th, 2004 |
5 | 5 | ||
6 | Copyright (C) 1998-2003 Gilles Vollant | 6 | Copyright (C) 1998-2004 Gilles Vollant |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <stdio.h> | 9 | #include <stdio.h> |
diff --git a/contrib/minizip/ioapi.h b/contrib/minizip/ioapi.h index 6bc2a2c..b761161 100644 --- a/contrib/minizip/ioapi.h +++ b/contrib/minizip/ioapi.h | |||
@@ -1,9 +1,9 @@ | |||
1 | /* ioapi.h -- IO base function header for compress/uncompress .zip | 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip |
2 | files using zlib + zip or unzip API | 2 | files using zlib + zip or unzip API |
3 | 3 | ||
4 | Version 1.00, September 10th, 2003 | 4 | Version 1.01, May 8th, 2004 |
5 | 5 | ||
6 | Copyright (C) 1998-2003 Gilles Vollant | 6 | Copyright (C) 1998-2004 Gilles Vollant |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #ifndef _ZLIBIOAPI_H | 9 | #ifndef _ZLIBIOAPI_H |
diff --git a/contrib/minizip/iowin32.c b/contrib/minizip/iowin32.c index 02b27cb..940dc0b 100644 --- a/contrib/minizip/iowin32.c +++ b/contrib/minizip/iowin32.c | |||
@@ -2,9 +2,9 @@ | |||
2 | files using zlib + zip or unzip API | 2 | files using zlib + zip or unzip API |
3 | This IO API version uses the Win32 API (for Microsoft Windows) | 3 | This IO API version uses the Win32 API (for Microsoft Windows) |
4 | 4 | ||
5 | Version 1.00, September 10th, 2003 | 5 | Version 1.01, May 8th, 2004 |
6 | 6 | ||
7 | Copyright (C) 1998-2003 Gilles Vollant | 7 | Copyright (C) 1998-2004 Gilles Vollant |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
diff --git a/contrib/minizip/iowin32.h b/contrib/minizip/iowin32.h index c0ebd50..8774fe7 100644 --- a/contrib/minizip/iowin32.h +++ b/contrib/minizip/iowin32.h | |||
@@ -2,9 +2,9 @@ | |||
2 | files using zlib + zip or unzip API | 2 | files using zlib + zip or unzip API |
3 | This IO API version uses the Win32 API (for Microsoft Windows) | 3 | This IO API version uses the Win32 API (for Microsoft Windows) |
4 | 4 | ||
5 | Version 1.00, September 10th, 2003 | 5 | Version 1.01, May 8th, 2004 |
6 | 6 | ||
7 | Copyright (C) 1998-2003 Gilles Vollant | 7 | Copyright (C) 1998-2004 Gilles Vollant |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <windows.h> | 10 | #include <windows.h> |
diff --git a/contrib/minizip/miniunz.c b/contrib/minizip/miniunz.c index c8cf81e..11b7260 100644 --- a/contrib/minizip/miniunz.c +++ b/contrib/minizip/miniunz.c | |||
@@ -1,3 +1,11 @@ | |||
1 | /* | ||
2 | miniunz.c | ||
3 | Version 1.01b, May 30th, 2004 | ||
4 | |||
5 | Copyright (C) 1998-2004 Gilles Vollant | ||
6 | */ | ||
7 | |||
8 | |||
1 | #include <stdio.h> | 9 | #include <stdio.h> |
2 | #include <stdlib.h> | 10 | #include <stdlib.h> |
3 | #include <string.h> | 11 | #include <string.h> |
@@ -27,7 +35,7 @@ | |||
27 | mini unzip, demo of unzip package | 35 | mini unzip, demo of unzip package |
28 | 36 | ||
29 | usage : | 37 | usage : |
30 | Usage : miniunz [-exvlo] file.zip [file_to_extract] | 38 | Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir] |
31 | 39 | ||
32 | list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT | 40 | list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT |
33 | if it exists | 41 | if it exists |
@@ -140,17 +148,18 @@ int makedir (newdir) | |||
140 | 148 | ||
141 | void do_banner() | 149 | void do_banner() |
142 | { | 150 | { |
143 | printf("MiniUnz 1.00, demo of zLib + Unz package written by Gilles Vollant\n"); | 151 | printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n"); |
144 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); | 152 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); |
145 | } | 153 | } |
146 | 154 | ||
147 | void do_help() | 155 | void do_help() |
148 | { | 156 | { |
149 | printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.]\n\n" \ | 157 | printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \ |
150 | " -e Extract without pathname (junk paths)\n" \ | 158 | " -e Extract without pathname (junk paths)\n" \ |
151 | " -x Extract with pathname\n" \ | 159 | " -x Extract with pathname\n" \ |
152 | " -v list files\n" \ | 160 | " -v list files\n" \ |
153 | " -l list files\n" \ | 161 | " -l list files\n" \ |
162 | " -d directory to extract into\n" \ | ||
154 | " -o overwrite files without prompting\n" \ | 163 | " -o overwrite files without prompting\n" \ |
155 | " -p extract crypted file using password\n\n"); | 164 | " -p extract crypted file using password\n\n"); |
156 | } | 165 | } |
@@ -304,8 +313,14 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password) | |||
304 | do | 313 | do |
305 | { | 314 | { |
306 | char answer[128]; | 315 | char answer[128]; |
307 | printf("The file %s exist. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename); | 316 | int ret; |
308 | scanf("%1s",answer); | 317 | |
318 | printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename); | ||
319 | ret = scanf("%1s",answer); | ||
320 | if (ret != 1) | ||
321 | { | ||
322 | exit(EXIT_FAILURE); | ||
323 | } | ||
309 | rep = answer[0] ; | 324 | rep = answer[0] ; |
310 | if ((rep>='a') && (rep<='z')) | 325 | if ((rep>='a') && (rep<='z')) |
311 | rep -= 0x20; | 326 | rep -= 0x20; |
@@ -459,6 +474,8 @@ int main(argc,argv) | |||
459 | int opt_do_extract=1; | 474 | int opt_do_extract=1; |
460 | int opt_do_extract_withoutpath=0; | 475 | int opt_do_extract_withoutpath=0; |
461 | int opt_overwrite=0; | 476 | int opt_overwrite=0; |
477 | int opt_extractdir=0; | ||
478 | const char *dirname=NULL; | ||
462 | unzFile uf=NULL; | 479 | unzFile uf=NULL; |
463 | 480 | ||
464 | do_banner(); | 481 | do_banner(); |
@@ -488,6 +505,12 @@ int main(argc,argv) | |||
488 | opt_do_extract = opt_do_extract_withoutpath = 1; | 505 | opt_do_extract = opt_do_extract_withoutpath = 1; |
489 | if ((c=='o') || (c=='O')) | 506 | if ((c=='o') || (c=='O')) |
490 | opt_overwrite=1; | 507 | opt_overwrite=1; |
508 | if ((c=='d') || (c=='D')) | ||
509 | { | ||
510 | opt_extractdir=1; | ||
511 | dirname=argv[i+1]; | ||
512 | } | ||
513 | |||
491 | if (((c=='p') || (c=='P')) && (i+1<argc)) | 514 | if (((c=='p') || (c=='P')) && (i+1<argc)) |
492 | { | 515 | { |
493 | password=argv[i+1]; | 516 | password=argv[i+1]; |
@@ -499,7 +522,7 @@ int main(argc,argv) | |||
499 | { | 522 | { |
500 | if (zipfilename == NULL) | 523 | if (zipfilename == NULL) |
501 | zipfilename = argv[i]; | 524 | zipfilename = argv[i]; |
502 | else if (filename_to_extract==NULL) | 525 | else if ((filename_to_extract==NULL) && (!opt_extractdir)) |
503 | filename_to_extract = argv[i] ; | 526 | filename_to_extract = argv[i] ; |
504 | } | 527 | } |
505 | } | 528 | } |
@@ -544,6 +567,12 @@ int main(argc,argv) | |||
544 | return do_list(uf); | 567 | return do_list(uf); |
545 | else if (opt_do_extract==1) | 568 | else if (opt_do_extract==1) |
546 | { | 569 | { |
570 | if (opt_extractdir && chdir(dirname)) | ||
571 | { | ||
572 | printf("Error changing into %s, aborting\n", dirname); | ||
573 | exit(-1); | ||
574 | } | ||
575 | |||
547 | if (filename_to_extract == NULL) | 576 | if (filename_to_extract == NULL) |
548 | return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password); | 577 | return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password); |
549 | else | 578 | else |
diff --git a/contrib/minizip/minizip.c b/contrib/minizip/minizip.c index 5746f5c..918c322 100644 --- a/contrib/minizip/minizip.c +++ b/contrib/minizip/minizip.c | |||
@@ -1,3 +1,10 @@ | |||
1 | /* | ||
2 | minizip.c | ||
3 | Version 1.01b, May 30th, 2004 | ||
4 | |||
5 | Copyright (C) 1998-2004 Gilles Vollant | ||
6 | */ | ||
7 | |||
1 | #include <stdio.h> | 8 | #include <stdio.h> |
2 | #include <stdlib.h> | 9 | #include <stdlib.h> |
3 | #include <string.h> | 10 | #include <string.h> |
@@ -53,8 +60,8 @@ uLong filetime(f, tmzip, dt) | |||
53 | #else | 60 | #else |
54 | #ifdef unix | 61 | #ifdef unix |
55 | uLong filetime(f, tmzip, dt) | 62 | uLong filetime(f, tmzip, dt) |
56 | char *f; /* name of file to get info on */ | 63 | char *f; /* name of file to get info on */ |
57 | tm_zip *tmzip; /* return value: access, modific. and creation times */ | 64 | tm_zip *tmzip; /* return value: access, modific. and creation times */ |
58 | uLong *dt; /* dostime */ | 65 | uLong *dt; /* dostime */ |
59 | { | 66 | { |
60 | int ret=0; | 67 | int ret=0; |
@@ -66,6 +73,8 @@ uLong filetime(f, tmzip, dt) | |||
66 | { | 73 | { |
67 | char name[MAXFILENAME+1]; | 74 | char name[MAXFILENAME+1]; |
68 | int len = strlen(f); | 75 | int len = strlen(f); |
76 | if (len > MAXFILENAME) | ||
77 | len = MAXFILENAME; | ||
69 | 78 | ||
70 | strncpy(name, f,MAXFILENAME-1); | 79 | strncpy(name, f,MAXFILENAME-1); |
71 | /* strncpy doesnt append the trailing NULL, of the string is too long. */ | 80 | /* strncpy doesnt append the trailing NULL, of the string is too long. */ |
@@ -120,7 +129,7 @@ int check_exist_file(filename) | |||
120 | 129 | ||
121 | void do_banner() | 130 | void do_banner() |
122 | { | 131 | { |
123 | printf("MiniZip 1.00, demo of zLib + Zip package written by Gilles Vollant\n"); | 132 | printf("MiniZip 1.01b, demo of zLib + Zip package written by Gilles Vollant\n"); |
124 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); | 133 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); |
125 | } | 134 | } |
126 | 135 | ||
@@ -269,8 +278,13 @@ int main(argc,argv) | |||
269 | do | 278 | do |
270 | { | 279 | { |
271 | char answer[128]; | 280 | char answer[128]; |
272 | printf("The file %s exist. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try); | 281 | int ret; |
273 | scanf("%1s",answer); | 282 | printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try); |
283 | ret = scanf("%1s",answer); | ||
284 | if (ret != 1) | ||
285 | { | ||
286 | exit(EXIT_FAILURE); | ||
287 | } | ||
274 | rep = answer[0] ; | 288 | rep = answer[0] ; |
275 | if ((rep>='a') && (rep<='z')) | 289 | if ((rep>='a') && (rep<='z')) |
276 | rep -= 0x20; | 290 | rep -= 0x20; |
@@ -305,7 +319,12 @@ int main(argc,argv) | |||
305 | 319 | ||
306 | for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++) | 320 | for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++) |
307 | { | 321 | { |
308 | if (((*(argv[i]))!='-') && ((*(argv[i]))!='/')) | 322 | if (!((((*(argv[i]))=='-') || ((*(argv[i]))=='/')) && |
323 | ((argv[i][1]=='o') || (argv[i][1]=='O') || | ||
324 | (argv[i][1]=='a') || (argv[i][1]=='A') || | ||
325 | (argv[i][1]=='p') || (argv[i][1]=='P') || | ||
326 | ((argv[i][1]>='0') || (argv[i][1]<='9'))) && | ||
327 | (strlen(argv[i]) == 2))) | ||
309 | { | 328 | { |
310 | FILE * fin; | 329 | FILE * fin; |
311 | int size_read; | 330 | int size_read; |
@@ -390,7 +409,11 @@ int main(argc,argv) | |||
390 | errclose = zipClose(zf,NULL); | 409 | errclose = zipClose(zf,NULL); |
391 | if (errclose != ZIP_OK) | 410 | if (errclose != ZIP_OK) |
392 | printf("error in closing %s\n",filename_try); | 411 | printf("error in closing %s\n",filename_try); |
393 | } | 412 | } |
413 | else | ||
414 | { | ||
415 | do_help(); | ||
416 | } | ||
394 | 417 | ||
395 | free(buf); | 418 | free(buf); |
396 | return 0; | 419 | return 0; |
diff --git a/contrib/minizip/mztools.c b/contrib/minizip/mztools.c new file mode 100644 index 0000000..363ee13 --- /dev/null +++ b/contrib/minizip/mztools.c | |||
@@ -0,0 +1,281 @@ | |||
1 | /* | ||
2 | Additional tools for Minizip | ||
3 | Code: Xavier Roche '2004 | ||
4 | License: Same as ZLIB (www.gzip.org) | ||
5 | */ | ||
6 | |||
7 | /* Code */ | ||
8 | #include <stdio.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <string.h> | ||
11 | #include "zlib.h" | ||
12 | #include "unzip.h" | ||
13 | |||
14 | #define READ_8(adr) ((unsigned char)*(adr)) | ||
15 | #define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) | ||
16 | #define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) | ||
17 | |||
18 | #define WRITE_8(buff, n) do { \ | ||
19 | *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ | ||
20 | } while(0) | ||
21 | #define WRITE_16(buff, n) do { \ | ||
22 | WRITE_8((unsigned char*)(buff), n); \ | ||
23 | WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ | ||
24 | } while(0) | ||
25 | #define WRITE_32(buff, n) do { \ | ||
26 | WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ | ||
27 | WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ | ||
28 | } while(0) | ||
29 | |||
30 | extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) | ||
31 | const char* file; | ||
32 | const char* fileOut; | ||
33 | const char* fileOutTmp; | ||
34 | uLong* nRecovered; | ||
35 | uLong* bytesRecovered; | ||
36 | { | ||
37 | int err = Z_OK; | ||
38 | FILE* fpZip = fopen(file, "rb"); | ||
39 | FILE* fpOut = fopen(fileOut, "wb"); | ||
40 | FILE* fpOutCD = fopen(fileOutTmp, "wb"); | ||
41 | if (fpZip != NULL && fpOut != NULL) { | ||
42 | int entries = 0; | ||
43 | uLong totalBytes = 0; | ||
44 | char header[30]; | ||
45 | char filename[256]; | ||
46 | char extra[1024]; | ||
47 | int offset = 0; | ||
48 | int offsetCD = 0; | ||
49 | while ( fread(header, 1, 30, fpZip) == 30 ) { | ||
50 | int currentOffset = offset; | ||
51 | |||
52 | /* File entry */ | ||
53 | if (READ_32(header) == 0x04034b50) { | ||
54 | unsigned int version = READ_16(header + 4); | ||
55 | unsigned int gpflag = READ_16(header + 6); | ||
56 | unsigned int method = READ_16(header + 8); | ||
57 | unsigned int filetime = READ_16(header + 10); | ||
58 | unsigned int filedate = READ_16(header + 12); | ||
59 | unsigned int crc = READ_32(header + 14); /* crc */ | ||
60 | unsigned int cpsize = READ_32(header + 18); /* compressed size */ | ||
61 | unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ | ||
62 | unsigned int fnsize = READ_16(header + 26); /* file name length */ | ||
63 | unsigned int extsize = READ_16(header + 28); /* extra field length */ | ||
64 | filename[0] = extra[0] = '\0'; | ||
65 | |||
66 | /* Header */ | ||
67 | if (fwrite(header, 1, 30, fpOut) == 30) { | ||
68 | offset += 30; | ||
69 | } else { | ||
70 | err = Z_ERRNO; | ||
71 | break; | ||
72 | } | ||
73 | |||
74 | /* Filename */ | ||
75 | if (fnsize > 0) { | ||
76 | if (fread(filename, 1, fnsize, fpZip) == fnsize) { | ||
77 | if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { | ||
78 | offset += fnsize; | ||
79 | } else { | ||
80 | err = Z_ERRNO; | ||
81 | break; | ||
82 | } | ||
83 | } else { | ||
84 | err = Z_ERRNO; | ||
85 | break; | ||
86 | } | ||
87 | } else { | ||
88 | err = Z_STREAM_ERROR; | ||
89 | break; | ||
90 | } | ||
91 | |||
92 | /* Extra field */ | ||
93 | if (extsize > 0) { | ||
94 | if (fread(extra, 1, extsize, fpZip) == extsize) { | ||
95 | if (fwrite(extra, 1, extsize, fpOut) == extsize) { | ||
96 | offset += extsize; | ||
97 | } else { | ||
98 | err = Z_ERRNO; | ||
99 | break; | ||
100 | } | ||
101 | } else { | ||
102 | err = Z_ERRNO; | ||
103 | break; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | /* Data */ | ||
108 | { | ||
109 | int dataSize = cpsize; | ||
110 | if (dataSize == 0) { | ||
111 | dataSize = uncpsize; | ||
112 | } | ||
113 | if (dataSize > 0) { | ||
114 | char* data = malloc(dataSize); | ||
115 | if (data != NULL) { | ||
116 | if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { | ||
117 | if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { | ||
118 | offset += dataSize; | ||
119 | totalBytes += dataSize; | ||
120 | } else { | ||
121 | err = Z_ERRNO; | ||
122 | } | ||
123 | } else { | ||
124 | err = Z_ERRNO; | ||
125 | } | ||
126 | free(data); | ||
127 | if (err != Z_OK) { | ||
128 | break; | ||
129 | } | ||
130 | } else { | ||
131 | err = Z_MEM_ERROR; | ||
132 | break; | ||
133 | } | ||
134 | } | ||
135 | } | ||
136 | |||
137 | /* Central directory entry */ | ||
138 | { | ||
139 | char header[46]; | ||
140 | char* comment = ""; | ||
141 | int comsize = (int) strlen(comment); | ||
142 | WRITE_32(header, 0x02014b50); | ||
143 | WRITE_16(header + 4, version); | ||
144 | WRITE_16(header + 6, version); | ||
145 | WRITE_16(header + 8, gpflag); | ||
146 | WRITE_16(header + 10, method); | ||
147 | WRITE_16(header + 12, filetime); | ||
148 | WRITE_16(header + 14, filedate); | ||
149 | WRITE_32(header + 16, crc); | ||
150 | WRITE_32(header + 20, cpsize); | ||
151 | WRITE_32(header + 24, uncpsize); | ||
152 | WRITE_16(header + 28, fnsize); | ||
153 | WRITE_16(header + 30, extsize); | ||
154 | WRITE_16(header + 32, comsize); | ||
155 | WRITE_16(header + 34, 0); /* disk # */ | ||
156 | WRITE_16(header + 36, 0); /* int attrb */ | ||
157 | WRITE_32(header + 38, 0); /* ext attrb */ | ||
158 | WRITE_32(header + 42, currentOffset); | ||
159 | /* Header */ | ||
160 | if (fwrite(header, 1, 46, fpOutCD) == 46) { | ||
161 | offsetCD += 46; | ||
162 | |||
163 | /* Filename */ | ||
164 | if (fnsize > 0) { | ||
165 | if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { | ||
166 | offsetCD += fnsize; | ||
167 | } else { | ||
168 | err = Z_ERRNO; | ||
169 | break; | ||
170 | } | ||
171 | } else { | ||
172 | err = Z_STREAM_ERROR; | ||
173 | break; | ||
174 | } | ||
175 | |||
176 | /* Extra field */ | ||
177 | if (extsize > 0) { | ||
178 | if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { | ||
179 | offsetCD += extsize; | ||
180 | } else { | ||
181 | err = Z_ERRNO; | ||
182 | break; | ||
183 | } | ||
184 | } | ||
185 | |||
186 | /* Comment field */ | ||
187 | if (comsize > 0) { | ||
188 | if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { | ||
189 | offsetCD += comsize; | ||
190 | } else { | ||
191 | err = Z_ERRNO; | ||
192 | break; | ||
193 | } | ||
194 | } | ||
195 | |||
196 | |||
197 | } else { | ||
198 | err = Z_ERRNO; | ||
199 | break; | ||
200 | } | ||
201 | } | ||
202 | |||
203 | /* Success */ | ||
204 | entries++; | ||
205 | |||
206 | } else { | ||
207 | break; | ||
208 | } | ||
209 | } | ||
210 | |||
211 | /* Final central directory */ | ||
212 | { | ||
213 | int entriesZip = entries; | ||
214 | char header[22]; | ||
215 | char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; | ||
216 | int comsize = (int) strlen(comment); | ||
217 | if (entriesZip > 0xffff) { | ||
218 | entriesZip = 0xffff; | ||
219 | } | ||
220 | WRITE_32(header, 0x06054b50); | ||
221 | WRITE_16(header + 4, 0); /* disk # */ | ||
222 | WRITE_16(header + 6, 0); /* disk # */ | ||
223 | WRITE_16(header + 8, entriesZip); /* hack */ | ||
224 | WRITE_16(header + 10, entriesZip); /* hack */ | ||
225 | WRITE_32(header + 12, offsetCD); /* size of CD */ | ||
226 | WRITE_32(header + 16, offset); /* offset to CD */ | ||
227 | WRITE_16(header + 20, comsize); /* comment */ | ||
228 | |||
229 | /* Header */ | ||
230 | if (fwrite(header, 1, 22, fpOutCD) == 22) { | ||
231 | |||
232 | /* Comment field */ | ||
233 | if (comsize > 0) { | ||
234 | if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { | ||
235 | err = Z_ERRNO; | ||
236 | } | ||
237 | } | ||
238 | |||
239 | } else { | ||
240 | err = Z_ERRNO; | ||
241 | } | ||
242 | } | ||
243 | |||
244 | /* Final merge (file + central directory) */ | ||
245 | fclose(fpOutCD); | ||
246 | if (err == Z_OK) { | ||
247 | fpOutCD = fopen(fileOutTmp, "rb"); | ||
248 | if (fpOutCD != NULL) { | ||
249 | int nRead; | ||
250 | char buffer[8192]; | ||
251 | while ( (nRead = fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { | ||
252 | if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { | ||
253 | err = Z_ERRNO; | ||
254 | break; | ||
255 | } | ||
256 | } | ||
257 | fclose(fpOutCD); | ||
258 | } | ||
259 | } | ||
260 | |||
261 | /* Close */ | ||
262 | fclose(fpZip); | ||
263 | fclose(fpOut); | ||
264 | |||
265 | /* Wipe temporary file */ | ||
266 | (void)remove(fileOutTmp); | ||
267 | |||
268 | /* Number of recovered entries */ | ||
269 | if (err == Z_OK) { | ||
270 | if (nRecovered != NULL) { | ||
271 | *nRecovered = entries; | ||
272 | } | ||
273 | if (bytesRecovered != NULL) { | ||
274 | *bytesRecovered = totalBytes; | ||
275 | } | ||
276 | } | ||
277 | } else { | ||
278 | err = Z_STREAM_ERROR; | ||
279 | } | ||
280 | return err; | ||
281 | } | ||
diff --git a/contrib/minizip/mztools.h b/contrib/minizip/mztools.h new file mode 100644 index 0000000..eee78dc --- /dev/null +++ b/contrib/minizip/mztools.h | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | Additional tools for Minizip | ||
3 | Code: Xavier Roche '2004 | ||
4 | License: Same as ZLIB (www.gzip.org) | ||
5 | */ | ||
6 | |||
7 | #ifndef _zip_tools_H | ||
8 | #define _zip_tools_H | ||
9 | |||
10 | #ifdef __cplusplus | ||
11 | extern "C" { | ||
12 | #endif | ||
13 | |||
14 | #ifndef _ZLIB_H | ||
15 | #include "zlib.h" | ||
16 | #endif | ||
17 | |||
18 | #include "unzip.h" | ||
19 | |||
20 | /* Repair a ZIP file (missing central directory) | ||
21 | file: file to recover | ||
22 | fileOut: output file after recovery | ||
23 | fileOutTmp: temporary file name used for recovery | ||
24 | */ | ||
25 | extern int ZEXPORT unzRepair(const char* file, | ||
26 | const char* fileOut, | ||
27 | const char* fileOutTmp, | ||
28 | uLong* nRecovered, | ||
29 | uLong* bytesRecovered); | ||
30 | |||
31 | #endif | ||
diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c index f08f624..e804a2a 100644 --- a/contrib/minizip/unzip.c +++ b/contrib/minizip/unzip.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* unzip.c -- IO for uncompress .zip files using zlib | 1 | /* unzip.c -- IO for uncompress .zip files using zlib |
2 | Version 1.00, September 10th, 2003 | 2 | Version 1.01c, August 23th, 2004 |
3 | 3 | ||
4 | Copyright (C) 1998-2003 Gilles Vollant | 4 | Copyright (C) 1998-2004 Gilles Vollant |
5 | 5 | ||
6 | Read unzip.h for more info | 6 | Read unzip.h for more info |
7 | */ | 7 | */ |
@@ -88,7 +88,7 @@ woven in by Terry Thorsen 1/2003. | |||
88 | 88 | ||
89 | 89 | ||
90 | const char unz_copyright[] = | 90 | const char unz_copyright[] = |
91 | " unzip 1.00 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll"; | 91 | " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; |
92 | 92 | ||
93 | /* unz_file_info_interntal contain internal info about a file in zipfile*/ | 93 | /* unz_file_info_interntal contain internal info about a file in zipfile*/ |
94 | typedef struct unz_file_info_internal_s | 94 | typedef struct unz_file_info_internal_s |
@@ -798,7 +798,8 @@ extern int ZEXPORT unzGoToNextFile (file) | |||
798 | s=(unz_s*)file; | 798 | s=(unz_s*)file; |
799 | if (!s->current_file_ok) | 799 | if (!s->current_file_ok) |
800 | return UNZ_END_OF_LIST_OF_FILE; | 800 | return UNZ_END_OF_LIST_OF_FILE; |
801 | if (s->num_file+1==s->gi.number_entry) | 801 | if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ |
802 | if (s->num_file+1==s->gi.number_entry) | ||
802 | return UNZ_END_OF_LIST_OF_FILE; | 803 | return UNZ_END_OF_LIST_OF_FILE; |
803 | 804 | ||
804 | s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + | 805 | s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + |
@@ -1244,9 +1245,15 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len) | |||
1244 | 1245 | ||
1245 | pfile_in_zip_read_info->stream.avail_out = (uInt)len; | 1246 | pfile_in_zip_read_info->stream.avail_out = (uInt)len; |
1246 | 1247 | ||
1247 | if (len>pfile_in_zip_read_info->rest_read_uncompressed) | 1248 | if ((len>pfile_in_zip_read_info->rest_read_uncompressed) && |
1249 | (!(pfile_in_zip_read_info->raw))) | ||
1248 | pfile_in_zip_read_info->stream.avail_out = | 1250 | pfile_in_zip_read_info->stream.avail_out = |
1249 | (uInt)pfile_in_zip_read_info->rest_read_uncompressed; | 1251 | (uInt)pfile_in_zip_read_info->rest_read_uncompressed; |
1252 | |||
1253 | if ((len>pfile_in_zip_read_info->rest_read_compressed) && | ||
1254 | (pfile_in_zip_read_info->raw)) | ||
1255 | pfile_in_zip_read_info->stream.avail_out = | ||
1256 | (uInt)pfile_in_zip_read_info->rest_read_compressed; | ||
1250 | 1257 | ||
1251 | while (pfile_in_zip_read_info->stream.avail_out>0) | 1258 | while (pfile_in_zip_read_info->stream.avail_out>0) |
1252 | { | 1259 | { |
@@ -1339,6 +1346,9 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len) | |||
1339 | */ | 1346 | */ |
1340 | err=inflate(&pfile_in_zip_read_info->stream,flush); | 1347 | err=inflate(&pfile_in_zip_read_info->stream,flush); |
1341 | 1348 | ||
1349 | if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL)) | ||
1350 | err = Z_DATA_ERROR; | ||
1351 | |||
1342 | uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; | 1352 | uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; |
1343 | uOutThis = uTotalOutAfter-uTotalOutBefore; | 1353 | uOutThis = uTotalOutAfter-uTotalOutBefore; |
1344 | 1354 | ||
@@ -1461,7 +1471,7 @@ extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) | |||
1461 | 1471 | ||
1462 | if (ZREAD(pfile_in_zip_read_info->z_filefunc, | 1472 | if (ZREAD(pfile_in_zip_read_info->z_filefunc, |
1463 | pfile_in_zip_read_info->filestream, | 1473 | pfile_in_zip_read_info->filestream, |
1464 | buf,size_to_read)!=size_to_read) | 1474 | buf,read_now)!=read_now) |
1465 | return UNZ_ERRNO; | 1475 | return UNZ_ERRNO; |
1466 | 1476 | ||
1467 | return (int)read_now; | 1477 | return (int)read_now; |
@@ -1544,3 +1554,40 @@ extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) | |||
1544 | *(szComment+s->gi.size_comment)='\0'; | 1554 | *(szComment+s->gi.size_comment)='\0'; |
1545 | return (int)uReadThis; | 1555 | return (int)uReadThis; |
1546 | } | 1556 | } |
1557 | |||
1558 | /* Additions by RX '2004 */ | ||
1559 | extern uLong ZEXPORT unzGetOffset (file) | ||
1560 | unzFile file; | ||
1561 | { | ||
1562 | unz_s* s; | ||
1563 | |||
1564 | if (file==NULL) | ||
1565 | return UNZ_PARAMERROR; | ||
1566 | s=(unz_s*)file; | ||
1567 | if (!s->current_file_ok) | ||
1568 | return 0; | ||
1569 | if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) | ||
1570 | if (s->num_file==s->gi.number_entry) | ||
1571 | return 0; | ||
1572 | return s->pos_in_central_dir; | ||
1573 | } | ||
1574 | |||
1575 | extern int ZEXPORT unzSetOffset (file, pos) | ||
1576 | unzFile file; | ||
1577 | uLong pos; | ||
1578 | { | ||
1579 | unz_s* s; | ||
1580 | int err; | ||
1581 | |||
1582 | if (file==NULL) | ||
1583 | return UNZ_PARAMERROR; | ||
1584 | s=(unz_s*)file; | ||
1585 | |||
1586 | s->pos_in_central_dir = pos; | ||
1587 | s->num_file = s->gi.number_entry; /* hack */ | ||
1588 | err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, | ||
1589 | &s->cur_file_info_internal, | ||
1590 | NULL,0,NULL,0,NULL,0); | ||
1591 | s->current_file_ok = (err == UNZ_OK); | ||
1592 | return err; | ||
1593 | } | ||
diff --git a/contrib/minizip/unzip.h b/contrib/minizip/unzip.h index 4e50979..0c7c6f1 100644 --- a/contrib/minizip/unzip.h +++ b/contrib/minizip/unzip.h | |||
@@ -1,7 +1,7 @@ | |||
1 | /* unzip.h -- IO for uncompress .zip files using zlib | 1 | /* unzip.h -- IO for uncompress .zip files using zlib |
2 | Version 1.00, September 10th, 2003 | 2 | Version 1.01, May 8th, 2004 |
3 | 3 | ||
4 | Copyright (C) 1998-2003 Gilles Vollant | 4 | Copyright (C) 1998-2004 Gilles Vollant |
5 | 5 | ||
6 | This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g | 6 | This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g |
7 | WinZip, InfoZip tools and compatible. | 7 | WinZip, InfoZip tools and compatible. |
@@ -335,6 +335,16 @@ extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, | |||
335 | the error code | 335 | the error code |
336 | */ | 336 | */ |
337 | 337 | ||
338 | /***************************************************************************/ | ||
339 | |||
340 | /* Get the current file offset */ | ||
341 | extern uLong ZEXPORT unzGetOffset (unzFile file); | ||
342 | |||
343 | /* Set the current file offset */ | ||
344 | extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); | ||
345 | |||
346 | |||
347 | |||
338 | #ifdef __cplusplus | 348 | #ifdef __cplusplus |
339 | } | 349 | } |
340 | #endif | 350 | #endif |
diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c index 1a713e5..ce1444c 100644 --- a/contrib/minizip/zip.c +++ b/contrib/minizip/zip.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* zip.c -- IO on .zip files using zlib | 1 | /* zip.c -- IO on .zip files using zlib |
2 | Version 1.00, September 10th, 2003 | 2 | Version 1.01, May 8th, 2004 |
3 | 3 | ||
4 | Copyright (C) 1998-2003 Gilles Vollant | 4 | Copyright (C) 1998-2004 Gilles Vollant |
5 | 5 | ||
6 | Read zip.h for more info | 6 | Read zip.h for more info |
7 | */ | 7 | */ |
@@ -77,7 +77,7 @@ | |||
77 | #endif | 77 | #endif |
78 | #endif | 78 | #endif |
79 | const char zip_copyright[] = | 79 | const char zip_copyright[] = |
80 | " zip 1.00 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll"; | 80 | " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; |
81 | 81 | ||
82 | 82 | ||
83 | #define SIZEDATA_INDATABLOCK (4096-(4*4)) | 83 | #define SIZEDATA_INDATABLOCK (4096-(4*4)) |
@@ -265,10 +265,19 @@ local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte) | |||
265 | { | 265 | { |
266 | unsigned char buf[4]; | 266 | unsigned char buf[4]; |
267 | int n; | 267 | int n; |
268 | for (n = 0; n < nbByte; n++) { | 268 | for (n = 0; n < nbByte; n++) |
269 | { | ||
269 | buf[n] = (unsigned char)(x & 0xff); | 270 | buf[n] = (unsigned char)(x & 0xff); |
270 | x >>= 8; | 271 | x >>= 8; |
271 | } | 272 | } |
273 | if (x != 0) | ||
274 | { /* data overflow - hack for ZIP64 (X Roche) */ | ||
275 | for (n = 0; n < nbByte; n++) | ||
276 | { | ||
277 | buf[n] = 0xff; | ||
278 | } | ||
279 | } | ||
280 | |||
272 | if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) | 281 | if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) |
273 | return ZIP_ERRNO; | 282 | return ZIP_ERRNO; |
274 | else | 283 | else |
@@ -287,7 +296,16 @@ local void ziplocal_putValue_inmemory (dest, x, nbByte) | |||
287 | buf[n] = (unsigned char)(x & 0xff); | 296 | buf[n] = (unsigned char)(x & 0xff); |
288 | x >>= 8; | 297 | x >>= 8; |
289 | } | 298 | } |
299 | |||
300 | if (x != 0) | ||
301 | { /* data overflow - hack for ZIP64 */ | ||
302 | for (n = 0; n < nbByte; n++) | ||
303 | { | ||
304 | buf[n] = 0xff; | ||
305 | } | ||
306 | } | ||
290 | } | 307 | } |
308 | |||
291 | /****************************************************************************/ | 309 | /****************************************************************************/ |
292 | 310 | ||
293 | 311 | ||
diff --git a/contrib/minizip/zip.h b/contrib/minizip/zip.h index c37ea21..d5112c4 100644 --- a/contrib/minizip/zip.h +++ b/contrib/minizip/zip.h | |||
@@ -1,7 +1,7 @@ | |||
1 | /* zip.h -- IO for compress .zip files using zlib | 1 | /* zip.h -- IO for compress .zip files using zlib |
2 | Version 1.00, September 10th, 2003 | 2 | Version 1.01, May 8th, 2004 |
3 | 3 | ||
4 | Copyright (C) 1998-2003 Gilles Vollant | 4 | Copyright (C) 1998-2004 Gilles Vollant |
5 | 5 | ||
6 | This unzip package allow creates .ZIP file, compatible with PKZip 2.04g | 6 | This unzip package allow creates .ZIP file, compatible with PKZip 2.04g |
7 | WinZip, InfoZip tools and compatible. | 7 | WinZip, InfoZip tools and compatible. |
@@ -212,7 +212,6 @@ extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); | |||
212 | Close the current file in the zipfile | 212 | Close the current file in the zipfile |
213 | */ | 213 | */ |
214 | 214 | ||
215 | |||
216 | extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, | 215 | extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, |
217 | uLong uncompressed_size, | 216 | uLong uncompressed_size, |
218 | uLong crc32)); | 217 | uLong crc32)); |