summaryrefslogtreecommitdiff
path: root/contrib/minizip/unzip.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/minizip/unzip.c')
-rw-r--r--contrib/minizip/unzip.c1283
1 files changed, 903 insertions, 380 deletions
diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c
index e115663..050d506 100644
--- a/contrib/minizip/unzip.c
+++ b/contrib/minizip/unzip.c
@@ -1,43 +1,75 @@
1/* unzip.c -- IO for uncompress .zip files using zlib 1/* unzip.c -- IO for uncompress .zip files using zlib
2 Version 1.01e, February 12th, 2005 2 Version 1.1, January 7th, 2010
3 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
3 4
4 Copyright (C) 1998-2005 Gilles Vollant 5 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
5 6
6 Read unzip.h for more info 7 Modifications of Unzip for Zip64
7*/ 8 Copyright (C) 2007-2008 Even Rouault
9
10 Modifications for Zip64 support on both zip and unzip
11 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
12
13 For more info read MiniZip_info.txt
14
15
16 ------------------------------------------------------------------------------------
17 Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
18 compatibility with older software. The following is from the original crypt.c.
19 Code woven in by Terry Thorsen 1/2003.
8 20
9/* Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
10compatibility with older software. The following is from the original crypt.c. Code
11woven in by Terry Thorsen 1/2003.
12*/
13/*
14 Copyright (c) 1990-2000 Info-ZIP. All rights reserved. 21 Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
15 22
16 See the accompanying file LICENSE, version 2000-Apr-09 or later 23 See the accompanying file LICENSE, version 2000-Apr-09 or later
17 (the contents of which are also included in zip.h) for terms of use. 24 (the contents of which are also included in zip.h) for terms of use.
18 If, for some reason, all these files are missing, the Info-ZIP license 25 If, for some reason, all these files are missing, the Info-ZIP license
19 also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html 26 also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
20*/ 27
21/* 28 crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
22 crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
23 29
24 The encryption/decryption parts of this source code (as opposed to the 30 The encryption/decryption parts of this source code (as opposed to the
25 non-echoing password parts) were originally written in Europe. The 31 non-echoing password parts) were originally written in Europe. The
26 whole source package can be freely distributed, including from the USA. 32 whole source package can be freely distributed, including from the USA.
27 (Prior to January 2000, re-export from the US was a violation of US law.) 33 (Prior to January 2000, re-export from the US was a violation of US law.)
28 */
29 34
30/* 35 This encryption code is a direct transcription of the algorithm from
31 This encryption code is a direct transcription of the algorithm from
32 Roger Schlafly, described by Phil Katz in the file appnote.txt. This 36 Roger Schlafly, described by Phil Katz in the file appnote.txt. This
33 file (appnote.txt) is distributed with the PKZIP program (even in the 37 file (appnote.txt) is distributed with the PKZIP program (even in the
34 version without encryption capabilities). 38 version without encryption capabilities).
35 */ 39
40 ------------------------------------------------------------------------------------
41
42 Changes in unzip64.c
43
44 2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos
45 2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz*
46 2007-2008 - Even Rouault - Remove old C style function prototypes
47 2007-2008 - Even Rouault - Add unzip support for ZIP64
48
49 Copyright (C) 2007-2008 Even Rouault
50
51
52 Okt-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again).
53 Okt-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G
54 should only read the compressed/uncompressed size from the Zip64 format if
55 the size from normal header was 0xFFFFFFFF
56 Okt-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant
57 Okt-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required)
58 Patch created by Daniel Borca
59
60 Copyright (C) 2009 Mathias Svensson
61
62*/
36 63
37 64
38#include <stdio.h> 65#include <stdio.h>
39#include <stdlib.h> 66#include <stdlib.h>
40#include <string.h> 67#include <string.h>
68
69#ifndef NOUNCRYPT
70 #define NOUNCRYPT
71#endif
72
41#include "zlib.h" 73#include "zlib.h"
42#include "unzip.h" 74#include "unzip.h"
43 75
@@ -85,16 +117,14 @@ woven in by Terry Thorsen 1/2003.
85#define SIZEZIPLOCALHEADER (0x1e) 117#define SIZEZIPLOCALHEADER (0x1e)
86 118
87 119
88
89
90const char unz_copyright[] = 120const char unz_copyright[] =
91 " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; 121 " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
92 122
93/* unz_file_info_interntal contain internal info about a file in zipfile*/ 123/* unz_file_info_interntal contain internal info about a file in zipfile*/
94typedef struct unz_file_info_internal_s 124typedef struct unz_file_info64_internal_s
95{ 125{
96 uLong offset_curfile;/* relative offset of local header 4 bytes */ 126 ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */
97} unz_file_info_internal; 127} unz_file_info64_internal;
98 128
99 129
100/* file_in_zip_read_info_s contain internal information about a file in zipfile, 130/* file_in_zip_read_info_s contain internal information about a file in zipfile,
@@ -104,52 +134,61 @@ typedef struct
104 char *read_buffer; /* internal buffer for compressed data */ 134 char *read_buffer; /* internal buffer for compressed data */
105 z_stream stream; /* zLib stream structure for inflate */ 135 z_stream stream; /* zLib stream structure for inflate */
106 136
107 uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ 137#ifdef HAVE_BZIP2
138 bz_stream bstream; /* bzLib stream structure for bziped */
139#endif
140
141 ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
108 uLong stream_initialised; /* flag set if stream structure is initialised*/ 142 uLong stream_initialised; /* flag set if stream structure is initialised*/
109 143
110 uLong offset_local_extrafield;/* offset of the local extra field */ 144 ZPOS64_T offset_local_extrafield;/* offset of the local extra field */
111 uInt size_local_extrafield;/* size of the local extra field */ 145 uInt size_local_extrafield;/* size of the local extra field */
112 uLong pos_local_extrafield; /* position in the local extra field in read*/ 146 ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/
147 ZPOS64_T total_out_64;
113 148
114 uLong crc32; /* crc32 of all data uncompressed */ 149 uLong crc32; /* crc32 of all data uncompressed */
115 uLong crc32_wait; /* crc32 we must obtain after decompress all */ 150 uLong crc32_wait; /* crc32 we must obtain after decompress all */
116 uLong rest_read_compressed; /* number of byte to be decompressed */ 151 ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */
117 uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/ 152 ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/
118 zlib_filefunc_def z_filefunc; 153 zlib_filefunc64_32_def z_filefunc;
119 voidpf filestream; /* io structore of the zipfile */ 154 voidpf filestream; /* io structore of the zipfile */
120 uLong compression_method; /* compression method (0==store) */ 155 uLong compression_method; /* compression method (0==store) */
121 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 156 ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
122 int raw; 157 int raw;
123} file_in_zip_read_info_s; 158} file_in_zip64_read_info_s;
124 159
125 160
126/* unz_s contain internal information about the zipfile 161/* unz64_s contain internal information about the zipfile
127*/ 162*/
128typedef struct 163typedef struct
129{ 164{
130 zlib_filefunc_def z_filefunc; 165 zlib_filefunc64_32_def z_filefunc;
166 int is64bitOpenFunction;
131 voidpf filestream; /* io structore of the zipfile */ 167 voidpf filestream; /* io structore of the zipfile */
132 unz_global_info gi; /* public global information */ 168 unz_global_info64 gi; /* public global information */
133 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 169 ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
134 uLong num_file; /* number of the current file in the zipfile*/ 170 ZPOS64_T num_file; /* number of the current file in the zipfile*/
135 uLong pos_in_central_dir; /* pos of the current file in the central dir*/ 171 ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/
136 uLong current_file_ok; /* flag about the usability of the current file*/ 172 ZPOS64_T current_file_ok; /* flag about the usability of the current file*/
137 uLong central_pos; /* position of the beginning of the central dir*/ 173 ZPOS64_T central_pos; /* position of the beginning of the central dir*/
138 174
139 uLong size_central_dir; /* size of the central directory */ 175 ZPOS64_T size_central_dir; /* size of the central directory */
140 uLong offset_central_dir; /* offset of start of central directory with 176 ZPOS64_T offset_central_dir; /* offset of start of central directory with
141 respect to the starting disk number */ 177 respect to the starting disk number */
142 178
143 unz_file_info cur_file_info; /* public info about the current file in zip*/ 179 unz_file_info64 cur_file_info; /* public info about the current file in zip*/
144 unz_file_info_internal cur_file_info_internal; /* private info about it*/ 180 unz_file_info64_internal cur_file_info_internal; /* private info about it*/
145 file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current 181 file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current
146 file if we are decompressing it */ 182 file if we are decompressing it */
147 int encrypted; 183 int encrypted;
184
185 int isZip64;
186
148# ifndef NOUNCRYPT 187# ifndef NOUNCRYPT
149 unsigned long keys[3]; /* keys defining the pseudo-random sequence */ 188 unsigned long keys[3]; /* keys defining the pseudo-random sequence */
150 const unsigned long* pcrc_32_tab; 189 const unsigned long* pcrc_32_tab;
151# endif 190# endif
152} unz_s; 191} unz64_s;
153 192
154 193
155#ifndef NOUNCRYPT 194#ifndef NOUNCRYPT
@@ -163,18 +202,15 @@ typedef struct
163*/ 202*/
164 203
165 204
166local int unzlocal_getByte OF(( 205local int unz64local_getByte OF((
167 const zlib_filefunc_def* pzlib_filefunc_def, 206 const zlib_filefunc64_32_def* pzlib_filefunc_def,
168 voidpf filestream, 207 voidpf filestream,
169 int *pi)); 208 int *pi));
170 209
171local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi) 210local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)
172 const zlib_filefunc_def* pzlib_filefunc_def;
173 voidpf filestream;
174 int *pi;
175{ 211{
176 unsigned char c; 212 unsigned char c;
177 int err = (int)ZREAD(*pzlib_filefunc_def,filestream,&c,1); 213 int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
178 if (err==1) 214 if (err==1)
179 { 215 {
180 *pi = (int)c; 216 *pi = (int)c;
@@ -182,7 +218,7 @@ local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
182 } 218 }
183 else 219 else
184 { 220 {
185 if (ZERROR(*pzlib_filefunc_def,filestream)) 221 if (ZERROR64(*pzlib_filefunc_def,filestream))
186 return UNZ_ERRNO; 222 return UNZ_ERRNO;
187 else 223 else
188 return UNZ_EOF; 224 return UNZ_EOF;
@@ -193,26 +229,25 @@ local int unzlocal_getByte(pzlib_filefunc_def,filestream,pi)
193/* =========================================================================== 229/* ===========================================================================
194 Reads a long in LSB order from the given gz_stream. Sets 230 Reads a long in LSB order from the given gz_stream. Sets
195*/ 231*/
196local int unzlocal_getShort OF(( 232local int unz64local_getShort OF((
197 const zlib_filefunc_def* pzlib_filefunc_def, 233 const zlib_filefunc64_32_def* pzlib_filefunc_def,
198 voidpf filestream, 234 voidpf filestream,
199 uLong *pX)); 235 uLong *pX));
200 236
201local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX) 237local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def,
202 const zlib_filefunc_def* pzlib_filefunc_def; 238 voidpf filestream,
203 voidpf filestream; 239 uLong *pX)
204 uLong *pX;
205{ 240{
206 uLong x ; 241 uLong x ;
207 int i; 242 int i = 0;
208 int err; 243 int err;
209 244
210 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 245 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
211 x = (uLong)i; 246 x = (uLong)i;
212 247
213 if (err==UNZ_OK) 248 if (err==UNZ_OK)
214 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 249 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
215 x += ((uLong)i)<<8; 250 x |= ((uLong)i)<<8;
216 251
217 if (err==UNZ_OK) 252 if (err==UNZ_OK)
218 *pX = x; 253 *pX = x;
@@ -221,33 +256,32 @@ local int unzlocal_getShort (pzlib_filefunc_def,filestream,pX)
221 return err; 256 return err;
222} 257}
223 258
224local int unzlocal_getLong OF(( 259local int unz64local_getLong OF((
225 const zlib_filefunc_def* pzlib_filefunc_def, 260 const zlib_filefunc64_32_def* pzlib_filefunc_def,
226 voidpf filestream, 261 voidpf filestream,
227 uLong *pX)); 262 uLong *pX));
228 263
229local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX) 264local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def,
230 const zlib_filefunc_def* pzlib_filefunc_def; 265 voidpf filestream,
231 voidpf filestream; 266 uLong *pX)
232 uLong *pX;
233{ 267{
234 uLong x ; 268 uLong x ;
235 int i; 269 int i = 0;
236 int err; 270 int err;
237 271
238 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 272 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
239 x = (uLong)i; 273 x = (uLong)i;
240 274
241 if (err==UNZ_OK) 275 if (err==UNZ_OK)
242 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 276 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
243 x += ((uLong)i)<<8; 277 x |= ((uLong)i)<<8;
244 278
245 if (err==UNZ_OK) 279 if (err==UNZ_OK)
246 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 280 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
247 x += ((uLong)i)<<16; 281 x |= ((uLong)i)<<16;
248 282
249 if (err==UNZ_OK) 283 if (err==UNZ_OK)
250 err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i); 284 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
251 x += ((uLong)i)<<24; 285 x += ((uLong)i)<<24;
252 286
253 if (err==UNZ_OK) 287 if (err==UNZ_OK)
@@ -257,11 +291,60 @@ local int unzlocal_getLong (pzlib_filefunc_def,filestream,pX)
257 return err; 291 return err;
258} 292}
259 293
294local int unz64local_getLong64 OF((
295 const zlib_filefunc64_32_def* pzlib_filefunc_def,
296 voidpf filestream,
297 ZPOS64_T *pX));
298
299
300local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def,
301 voidpf filestream,
302 ZPOS64_T *pX)
303{
304 ZPOS64_T x ;
305 int i = 0;
306 int err;
307
308 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
309 x = (ZPOS64_T)i;
310
311 if (err==UNZ_OK)
312 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
313 x |= ((ZPOS64_T)i)<<8;
314
315 if (err==UNZ_OK)
316 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
317 x |= ((ZPOS64_T)i)<<16;
318
319 if (err==UNZ_OK)
320 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
321 x |= ((ZPOS64_T)i)<<24;
322
323 if (err==UNZ_OK)
324 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
325 x |= ((ZPOS64_T)i)<<32;
326
327 if (err==UNZ_OK)
328 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
329 x |= ((ZPOS64_T)i)<<40;
330
331 if (err==UNZ_OK)
332 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
333 x |= ((ZPOS64_T)i)<<48;
334
335 if (err==UNZ_OK)
336 err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
337 x |= ((ZPOS64_T)i)<<56;
338
339 if (err==UNZ_OK)
340 *pX = x;
341 else
342 *pX = 0;
343 return err;
344}
260 345
261/* My own strcmpi / strcasecmp */ 346/* My own strcmpi / strcasecmp */
262local int strcmpcasenosensitive_internal (fileName1,fileName2) 347local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2)
263 const char* fileName1;
264 const char* fileName2;
265{ 348{
266 for (;;) 349 for (;;)
267 { 350 {
@@ -302,10 +385,10 @@ local int strcmpcasenosensitive_internal (fileName1,fileName2)
302 (like 1 on Unix, 2 on Windows) 385 (like 1 on Unix, 2 on Windows)
303 386
304*/ 387*/
305extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity) 388extern int ZEXPORT unzStringFileNameCompare (const char* fileName1,
306 const char* fileName1; 389 const char* fileName2,
307 const char* fileName2; 390 int iCaseSensitivity)
308 int iCaseSensitivity; 391
309{ 392{
310 if (iCaseSensitivity==0) 393 if (iCaseSensitivity==0)
311 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; 394 iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
@@ -324,25 +407,20 @@ extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivit
324 Locate the Central directory of a zipfile (at the end, just before 407 Locate the Central directory of a zipfile (at the end, just before
325 the global comment) 408 the global comment)
326*/ 409*/
327local uLong unzlocal_SearchCentralDir OF(( 410local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
328 const zlib_filefunc_def* pzlib_filefunc_def, 411local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
329 voidpf filestream));
330
331local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
332 const zlib_filefunc_def* pzlib_filefunc_def;
333 voidpf filestream;
334{ 412{
335 unsigned char* buf; 413 unsigned char* buf;
336 uLong uSizeFile; 414 ZPOS64_T uSizeFile;
337 uLong uBackRead; 415 ZPOS64_T uBackRead;
338 uLong uMaxBack=0xffff; /* maximum size of global comment */ 416 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
339 uLong uPosFound=0; 417 ZPOS64_T uPosFound=0;
340 418
341 if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) 419 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
342 return 0; 420 return 0;
343 421
344 422
345 uSizeFile = ZTELL(*pzlib_filefunc_def,filestream); 423 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
346 424
347 if (uMaxBack>uSizeFile) 425 if (uMaxBack>uSizeFile)
348 uMaxBack = uSizeFile; 426 uMaxBack = uSizeFile;
@@ -354,7 +432,8 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
354 uBackRead = 4; 432 uBackRead = 4;
355 while (uBackRead<uMaxBack) 433 while (uBackRead<uMaxBack)
356 { 434 {
357 uLong uReadSize,uReadPos ; 435 uLong uReadSize;
436 ZPOS64_T uReadPos ;
358 int i; 437 int i;
359 if (uBackRead+BUFREADCOMMENT>uMaxBack) 438 if (uBackRead+BUFREADCOMMENT>uMaxBack)
360 uBackRead = uMaxBack; 439 uBackRead = uMaxBack;
@@ -363,11 +442,11 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
363 uReadPos = uSizeFile-uBackRead ; 442 uReadPos = uSizeFile-uBackRead ;
364 443
365 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? 444 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
366 (BUFREADCOMMENT+4) : (uSizeFile-uReadPos); 445 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
367 if (ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) 446 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
368 break; 447 break;
369 448
370 if (ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) 449 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
371 break; 450 break;
372 451
373 for (i=(int)uReadSize-3; (i--)>0;) 452 for (i=(int)uReadSize-3; (i--)>0;)
@@ -385,6 +464,112 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
385 return uPosFound; 464 return uPosFound;
386} 465}
387 466
467
468/*
469 Locate the Central directory 64 of a zipfile (at the end, just before
470 the global comment)
471*/
472local ZPOS64_T unz64local_SearchCentralDir64 OF((
473 const zlib_filefunc64_32_def* pzlib_filefunc_def,
474 voidpf filestream));
475
476local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
477 voidpf filestream)
478{
479 unsigned char* buf;
480 ZPOS64_T uSizeFile;
481 ZPOS64_T uBackRead;
482 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
483 ZPOS64_T uPosFound=0;
484 uLong uL;
485 ZPOS64_T relativeOffset;
486
487 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
488 return 0;
489
490
491 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
492
493 if (uMaxBack>uSizeFile)
494 uMaxBack = uSizeFile;
495
496 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
497 if (buf==NULL)
498 return 0;
499
500 uBackRead = 4;
501 while (uBackRead<uMaxBack)
502 {
503 uLong uReadSize;
504 ZPOS64_T uReadPos;
505 int i;
506 if (uBackRead+BUFREADCOMMENT>uMaxBack)
507 uBackRead = uMaxBack;
508 else
509 uBackRead+=BUFREADCOMMENT;
510 uReadPos = uSizeFile-uBackRead ;
511
512 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
513 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
514 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
515 break;
516
517 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
518 break;
519
520 for (i=(int)uReadSize-3; (i--)>0;)
521 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
522 ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
523 {
524 uPosFound = uReadPos+i;
525 break;
526 }
527
528 if (uPosFound!=0)
529 break;
530 }
531 TRYFREE(buf);
532 if (uPosFound == 0)
533 return 0;
534
535 /* Zip64 end of central directory locator */
536 if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
537 return 0;
538
539 /* the signature, already checked */
540 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
541 return 0;
542
543 /* number of the disk with the start of the zip64 end of central directory */
544 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
545 return 0;
546 if (uL != 0)
547 return 0;
548
549 /* relative offset of the zip64 end of central directory record */
550 if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
551 return 0;
552
553 /* total number of disks */
554 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
555 return 0;
556 if (uL != 1)
557 return 0;
558
559 /* Goto end of central directory record */
560 if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
561 return 0;
562
563 /* the signature */
564 if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
565 return 0;
566
567 if (uL != 0x06064b50)
568 return 0;
569
570 return relativeOffset;
571}
572
388/* 573/*
389 Open a Zip file. path contain the full pathname (by example, 574 Open a Zip file. path contain the full pathname (by example,
390 on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer 575 on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
@@ -394,19 +579,20 @@ local uLong unzlocal_SearchCentralDir(pzlib_filefunc_def,filestream)
394 Else, the return value is a unzFile Handle, usable with other function 579 Else, the return value is a unzFile Handle, usable with other function
395 of this unzip package. 580 of this unzip package.
396*/ 581*/
397extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def) 582local unzFile unzOpenInternal (const void *path,
398 const char *path; 583 zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
399 zlib_filefunc_def* pzlib_filefunc_def; 584 int is64bitOpenFunction)
400{ 585{
401 unz_s us; 586 unz64_s us;
402 unz_s *s; 587 unz64_s *s;
403 uLong central_pos,uL; 588 ZPOS64_T central_pos;
589 uLong uL;
404 590
405 uLong number_disk; /* number of the current dist, used for 591 uLong number_disk; /* number of the current dist, used for
406 spaning ZIP, unsupported, always 0*/ 592 spaning ZIP, unsupported, always 0*/
407 uLong number_disk_with_CD; /* number the the disk with central dir, used 593 uLong number_disk_with_CD; /* number the the disk with central dir, used
408 for spaning ZIP, unsupported, always 0*/ 594 for spaning ZIP, unsupported, always 0*/
409 uLong number_entry_CD; /* total number of entries in 595 ZPOS64_T number_entry_CD; /* total number of entries in
410 the central dir 596 the central dir
411 (same than number_entry on nospan) */ 597 (same than number_entry on nospan) */
412 598
@@ -415,63 +601,137 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
415 if (unz_copyright[0]!=' ') 601 if (unz_copyright[0]!=' ')
416 return NULL; 602 return NULL;
417 603
418 if (pzlib_filefunc_def==NULL) 604 us.z_filefunc.zseek32_file = NULL;
419 fill_fopen_filefunc(&us.z_filefunc); 605 us.z_filefunc.ztell32_file = NULL;
606 if (pzlib_filefunc64_32_def==NULL)
607 fill_fopen64_filefunc(&us.z_filefunc.zfile_func64);
420 else 608 else
421 us.z_filefunc = *pzlib_filefunc_def; 609 us.z_filefunc = *pzlib_filefunc64_32_def;
610 us.is64bitOpenFunction = is64bitOpenFunction;
611
612
422 613
423 us.filestream= (*(us.z_filefunc.zopen_file))(us.z_filefunc.opaque, 614 us.filestream = ZOPEN64(us.z_filefunc,
424 path, 615 path,
425 ZLIB_FILEFUNC_MODE_READ | 616 ZLIB_FILEFUNC_MODE_READ |
426 ZLIB_FILEFUNC_MODE_EXISTING); 617 ZLIB_FILEFUNC_MODE_EXISTING);
427 if (us.filestream==NULL) 618 if (us.filestream==NULL)
428 return NULL; 619 return NULL;
429 620
430 central_pos = unzlocal_SearchCentralDir(&us.z_filefunc,us.filestream); 621 central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
431 if (central_pos==0) 622 if (central_pos)
432 err=UNZ_ERRNO; 623 {
624 uLong uS;
625 ZPOS64_T uL64;
626
627 us.isZip64 = 1;
433 628
434 if (ZSEEK(us.z_filefunc, us.filestream, 629 if (ZSEEK64(us.z_filefunc, us.filestream,
435 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) 630 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
436 err=UNZ_ERRNO; 631 err=UNZ_ERRNO;
437 632
438 /* the signature, already checked */ 633 /* the signature, already checked */
439 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) 634 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
440 err=UNZ_ERRNO; 635 err=UNZ_ERRNO;
441 636
442 /* number of this disk */ 637 /* size of zip64 end of central directory record */
443 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) 638 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK)
444 err=UNZ_ERRNO; 639 err=UNZ_ERRNO;
445 640
446 /* number of the disk with the start of the central directory */ 641 /* version made by */
447 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) 642 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
448 err=UNZ_ERRNO; 643 err=UNZ_ERRNO;
449 644
450 /* total number of entries in the central dir on this disk */ 645 /* version needed to extract */
451 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) 646 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
452 err=UNZ_ERRNO; 647 err=UNZ_ERRNO;
453 648
454 /* total number of entries in the central dir */ 649 /* number of this disk */
455 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) 650 if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
456 err=UNZ_ERRNO; 651 err=UNZ_ERRNO;
457 652
458 if ((number_entry_CD!=us.gi.number_entry) || 653 /* number of the disk with the start of the central directory */
459 (number_disk_with_CD!=0) || 654 if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
460 (number_disk!=0)) 655 err=UNZ_ERRNO;
461 err=UNZ_BADZIPFILE;
462 656
463 /* size of the central directory */ 657 /* total number of entries in the central directory on this disk */
464 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) 658 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
465 err=UNZ_ERRNO; 659 err=UNZ_ERRNO;
660
661 /* total number of entries in the central directory */
662 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
663 err=UNZ_ERRNO;
664
665 if ((number_entry_CD!=us.gi.number_entry) ||
666 (number_disk_with_CD!=0) ||
667 (number_disk!=0))
668 err=UNZ_BADZIPFILE;
669
670 /* size of the central directory */
671 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
672 err=UNZ_ERRNO;
466 673
467 /* offset of start of central directory with respect to the 674 /* offset of start of central directory with respect to the
468 starting disk number */ 675 starting disk number */
469 if (unzlocal_getLong(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) 676 if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
470 err=UNZ_ERRNO; 677 err=UNZ_ERRNO;
471 678
472 /* zipfile comment length */ 679 us.gi.size_comment = 0;
473 if (unzlocal_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) 680 }
474 err=UNZ_ERRNO; 681 else
682 {
683 central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
684 if (central_pos==0)
685 err=UNZ_ERRNO;
686
687 us.isZip64 = 0;
688
689 if (ZSEEK64(us.z_filefunc, us.filestream,
690 central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
691 err=UNZ_ERRNO;
692
693 /* the signature, already checked */
694 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
695 err=UNZ_ERRNO;
696
697 /* number of this disk */
698 if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
699 err=UNZ_ERRNO;
700
701 /* number of the disk with the start of the central directory */
702 if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
703 err=UNZ_ERRNO;
704
705 /* total number of entries in the central dir on this disk */
706 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
707 err=UNZ_ERRNO;
708 us.gi.number_entry = uL;
709
710 /* total number of entries in the central dir */
711 if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
712 err=UNZ_ERRNO;
713 number_entry_CD = uL;
714
715 if ((number_entry_CD!=us.gi.number_entry) ||
716 (number_disk_with_CD!=0) ||
717 (number_disk!=0))
718 err=UNZ_BADZIPFILE;
719
720 /* size of the central directory */
721 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
722 err=UNZ_ERRNO;
723 us.size_central_dir = uL;
724
725 /* offset of start of central directory with respect to the
726 starting disk number */
727 if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
728 err=UNZ_ERRNO;
729 us.offset_central_dir = uL;
730
731 /* zipfile comment length */
732 if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
733 err=UNZ_ERRNO;
734 }
475 735
476 if ((central_pos<us.offset_central_dir+us.size_central_dir) && 736 if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
477 (err==UNZ_OK)) 737 (err==UNZ_OK))
@@ -479,7 +739,7 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
479 739
480 if (err!=UNZ_OK) 740 if (err!=UNZ_OK)
481 { 741 {
482 ZCLOSE(us.z_filefunc, us.filestream); 742 ZCLOSE64(us.z_filefunc, us.filestream);
483 return NULL; 743 return NULL;
484 } 744 }
485 745
@@ -490,17 +750,52 @@ extern unzFile ZEXPORT unzOpen2 (path, pzlib_filefunc_def)
490 us.encrypted = 0; 750 us.encrypted = 0;
491 751
492 752
493 s=(unz_s*)ALLOC(sizeof(unz_s)); 753 s=(unz64_s*)ALLOC(sizeof(unz64_s));
494 *s=us; 754 if( s != NULL)
495 unzGoToFirstFile((unzFile)s); 755 {
756 *s=us;
757 unzGoToFirstFile((unzFile)s);
758 }
496 return (unzFile)s; 759 return (unzFile)s;
497} 760}
498 761
499 762
500extern unzFile ZEXPORT unzOpen (path) 763extern unzFile ZEXPORT unzOpen2 (const char *path,
501 const char *path; 764 zlib_filefunc_def* pzlib_filefunc32_def)
502{ 765{
503 return unzOpen2(path, NULL); 766 if (pzlib_filefunc32_def != NULL)
767 {
768 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
769 fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
770 return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0);
771 }
772 else
773 return unzOpenInternal(path, NULL, 0);
774}
775
776extern unzFile ZEXPORT unzOpen2_64 (const void *path,
777 zlib_filefunc64_def* pzlib_filefunc_def)
778{
779 if (pzlib_filefunc_def != NULL)
780 {
781 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
782 zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
783 zlib_filefunc64_32_def_fill.ztell32_file = NULL;
784 zlib_filefunc64_32_def_fill.zseek32_file = NULL;
785 return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 1);
786 }
787 else
788 return unzOpenInternal(path, NULL, 1);
789}
790
791extern unzFile ZEXPORT unzOpen (const char *path)
792{
793 return unzOpenInternal(path, NULL, 0);
794}
795
796extern unzFile ZEXPORT unzOpen64 (const void *path)
797{
798 return unzOpenInternal(path, NULL, 1);
504} 799}
505 800
506/* 801/*
@@ -508,18 +803,17 @@ extern unzFile ZEXPORT unzOpen (path)
508 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later), 803 If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
509 these files MUST be closed with unzipCloseCurrentFile before call unzipClose. 804 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
510 return UNZ_OK if there is no problem. */ 805 return UNZ_OK if there is no problem. */
511extern int ZEXPORT unzClose (file) 806extern int ZEXPORT unzClose (unzFile file)
512 unzFile file;
513{ 807{
514 unz_s* s; 808 unz64_s* s;
515 if (file==NULL) 809 if (file==NULL)
516 return UNZ_PARAMERROR; 810 return UNZ_PARAMERROR;
517 s=(unz_s*)file; 811 s=(unz64_s*)file;
518 812
519 if (s->pfile_in_zip_read!=NULL) 813 if (s->pfile_in_zip_read!=NULL)
520 unzCloseCurrentFile(file); 814 unzCloseCurrentFile(file);
521 815
522 ZCLOSE(s->z_filefunc, s->filestream); 816 ZCLOSE64(s->z_filefunc, s->filestream);
523 TRYFREE(s); 817 TRYFREE(s);
524 return UNZ_OK; 818 return UNZ_OK;
525} 819}
@@ -529,28 +823,34 @@ extern int ZEXPORT unzClose (file)
529 Write info about the ZipFile in the *pglobal_info structure. 823 Write info about the ZipFile in the *pglobal_info structure.
530 No preparation of the structure is needed 824 No preparation of the structure is needed
531 return UNZ_OK if there is no problem. */ 825 return UNZ_OK if there is no problem. */
532extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info) 826extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info)
533 unzFile file;
534 unz_global_info *pglobal_info;
535{ 827{
536 unz_s* s; 828 unz64_s* s;
537 if (file==NULL) 829 if (file==NULL)
538 return UNZ_PARAMERROR; 830 return UNZ_PARAMERROR;
539 s=(unz_s*)file; 831 s=(unz64_s*)file;
540 *pglobal_info=s->gi; 832 *pglobal_info=s->gi;
541 return UNZ_OK; 833 return UNZ_OK;
542} 834}
543 835
544 836extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32)
837{
838 unz64_s* s;
839 if (file==NULL)
840 return UNZ_PARAMERROR;
841 s=(unz64_s*)file;
842 /* to do : check if number_entry is not truncated */
843 pglobal_info32->number_entry = (uLong)s->gi.number_entry;
844 pglobal_info32->size_comment = s->gi.size_comment;
845 return UNZ_OK;
846}
545/* 847/*
546 Translate date/time from Dos format to tm_unz (readable more easilty) 848 Translate date/time from Dos format to tm_unz (readable more easilty)
547*/ 849*/
548local void unzlocal_DosDateToTmuDate (ulDosDate, ptm) 850local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
549 uLong ulDosDate;
550 tm_unz* ptm;
551{ 851{
552 uLong uDate; 852 ZPOS64_T uDate;
553 uDate = (uLong)(ulDosDate>>16); 853 uDate = (ZPOS64_T)(ulDosDate>>16);
554 ptm->tm_mday = (uInt)(uDate&0x1f) ; 854 ptm->tm_mday = (uInt)(uDate&0x1f) ;
555 ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; 855 ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ;
556 ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; 856 ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ;
@@ -563,9 +863,9 @@ local void unzlocal_DosDateToTmuDate (ulDosDate, ptm)
563/* 863/*
564 Get Info about the current file in the zipfile, with internal only info 864 Get Info about the current file in the zipfile, with internal only info
565*/ 865*/
566local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file, 866local int unz64local_GetCurrentFileInfoInternal OF((unzFile file,
567 unz_file_info *pfile_info, 867 unz_file_info64 *pfile_info,
568 unz_file_info_internal 868 unz_file_info64_internal
569 *pfile_info_internal, 869 *pfile_info_internal,
570 char *szFileName, 870 char *szFileName,
571 uLong fileNameBufferSize, 871 uLong fileNameBufferSize,
@@ -574,33 +874,29 @@ local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
574 char *szComment, 874 char *szComment,
575 uLong commentBufferSize)); 875 uLong commentBufferSize));
576 876
577local int unzlocal_GetCurrentFileInfoInternal (file, 877local int unz64local_GetCurrentFileInfoInternal (unzFile file,
578 pfile_info, 878 unz_file_info64 *pfile_info,
579 pfile_info_internal, 879 unz_file_info64_internal
580 szFileName, fileNameBufferSize, 880 *pfile_info_internal,
581 extraField, extraFieldBufferSize, 881 char *szFileName,
582 szComment, commentBufferSize) 882 uLong fileNameBufferSize,
583 unzFile file; 883 void *extraField,
584 unz_file_info *pfile_info; 884 uLong extraFieldBufferSize,
585 unz_file_info_internal *pfile_info_internal; 885 char *szComment,
586 char *szFileName; 886 uLong commentBufferSize)
587 uLong fileNameBufferSize;
588 void *extraField;
589 uLong extraFieldBufferSize;
590 char *szComment;
591 uLong commentBufferSize;
592{ 887{
593 unz_s* s; 888 unz64_s* s;
594 unz_file_info file_info; 889 unz_file_info64 file_info;
595 unz_file_info_internal file_info_internal; 890 unz_file_info64_internal file_info_internal;
596 int err=UNZ_OK; 891 int err=UNZ_OK;
597 uLong uMagic; 892 uLong uMagic;
598 long lSeek=0; 893 long lSeek=0;
894 uLong uL;
599 895
600 if (file==NULL) 896 if (file==NULL)
601 return UNZ_PARAMERROR; 897 return UNZ_PARAMERROR;
602 s=(unz_s*)file; 898 s=(unz64_s*)file;
603 if (ZSEEK(s->z_filefunc, s->filestream, 899 if (ZSEEK64(s->z_filefunc, s->filestream,
604 s->pos_in_central_dir+s->byte_before_the_zipfile, 900 s->pos_in_central_dir+s->byte_before_the_zipfile,
605 ZLIB_FILEFUNC_SEEK_SET)!=0) 901 ZLIB_FILEFUNC_SEEK_SET)!=0)
606 err=UNZ_ERRNO; 902 err=UNZ_ERRNO;
@@ -608,57 +904,63 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
608 904
609 /* we check the magic */ 905 /* we check the magic */
610 if (err==UNZ_OK) 906 if (err==UNZ_OK)
611 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) 907 {
908 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
612 err=UNZ_ERRNO; 909 err=UNZ_ERRNO;
613 else if (uMagic!=0x02014b50) 910 else if (uMagic!=0x02014b50)
614 err=UNZ_BADZIPFILE; 911 err=UNZ_BADZIPFILE;
912 }
615 913
616 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) 914 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
617 err=UNZ_ERRNO; 915 err=UNZ_ERRNO;
618 916
619 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) 917 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
620 err=UNZ_ERRNO; 918 err=UNZ_ERRNO;
621 919
622 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) 920 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
623 err=UNZ_ERRNO; 921 err=UNZ_ERRNO;
624 922
625 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) 923 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
626 err=UNZ_ERRNO; 924 err=UNZ_ERRNO;
627 925
628 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) 926 if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
629 err=UNZ_ERRNO; 927 err=UNZ_ERRNO;
630 928
631 unzlocal_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); 929 unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
632 930
633 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) 931 if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
634 err=UNZ_ERRNO; 932 err=UNZ_ERRNO;
635 933
636 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) 934 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
637 err=UNZ_ERRNO; 935 err=UNZ_ERRNO;
936 file_info.compressed_size = uL;
638 937
639 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) 938 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
640 err=UNZ_ERRNO; 939 err=UNZ_ERRNO;
940 file_info.uncompressed_size = uL;
641 941
642 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) 942 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
643 err=UNZ_ERRNO; 943 err=UNZ_ERRNO;
644 944
645 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) 945 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
646 err=UNZ_ERRNO; 946 err=UNZ_ERRNO;
647 947
648 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) 948 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
649 err=UNZ_ERRNO; 949 err=UNZ_ERRNO;
650 950
651 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) 951 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
652 err=UNZ_ERRNO; 952 err=UNZ_ERRNO;
653 953
654 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) 954 if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
655 err=UNZ_ERRNO; 955 err=UNZ_ERRNO;
656 956
657 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) 957 if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
658 err=UNZ_ERRNO; 958 err=UNZ_ERRNO;
659 959
660 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) 960 // relative offset of local header
961 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
661 err=UNZ_ERRNO; 962 err=UNZ_ERRNO;
963 file_info_internal.offset_curfile = uL;
662 964
663 lSeek+=file_info.size_filename; 965 lSeek+=file_info.size_filename;
664 if ((err==UNZ_OK) && (szFileName!=NULL)) 966 if ((err==UNZ_OK) && (szFileName!=NULL))
@@ -673,33 +975,105 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
673 uSizeRead = fileNameBufferSize; 975 uSizeRead = fileNameBufferSize;
674 976
675 if ((file_info.size_filename>0) && (fileNameBufferSize>0)) 977 if ((file_info.size_filename>0) && (fileNameBufferSize>0))
676 if (ZREAD(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) 978 if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
677 err=UNZ_ERRNO; 979 err=UNZ_ERRNO;
678 lSeek -= uSizeRead; 980 lSeek -= uSizeRead;
679 } 981 }
680 982
681 983 // Read extrafield
682 if ((err==UNZ_OK) && (extraField!=NULL)) 984 if ((err==UNZ_OK) && (extraField!=NULL))
683 { 985 {
684 uLong uSizeRead ; 986 ZPOS64_T uSizeRead ;
685 if (file_info.size_file_extra<extraFieldBufferSize) 987 if (file_info.size_file_extra<extraFieldBufferSize)
686 uSizeRead = file_info.size_file_extra; 988 uSizeRead = file_info.size_file_extra;
687 else 989 else
688 uSizeRead = extraFieldBufferSize; 990 uSizeRead = extraFieldBufferSize;
689 991
690 if (lSeek!=0) 992 if (lSeek!=0)
691 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) 993 {
994 if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
692 lSeek=0; 995 lSeek=0;
693 else 996 else
694 err=UNZ_ERRNO; 997 err=UNZ_ERRNO;
998 }
999
695 if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) 1000 if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
696 if (ZREAD(s->z_filefunc, s->filestream,extraField,uSizeRead)!=uSizeRead) 1001 if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead)
697 err=UNZ_ERRNO; 1002 err=UNZ_ERRNO;
698 lSeek += file_info.size_file_extra - uSizeRead; 1003
1004 lSeek += file_info.size_file_extra - (uLong)uSizeRead;
699 } 1005 }
700 else 1006 else
701 lSeek+=file_info.size_file_extra; 1007 lSeek += file_info.size_file_extra;
1008
1009
1010 if ((err==UNZ_OK) && (file_info.size_file_extra != 0))
1011 {
1012 uLong acc = 0;
1013
1014 // since lSeek now points to after the extra field we need to move back
1015 lSeek -= file_info.size_file_extra;
1016
1017 if (lSeek!=0)
1018 {
1019 if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
1020 lSeek=0;
1021 else
1022 err=UNZ_ERRNO;
1023 }
1024
1025 while(acc < file_info.size_file_extra)
1026 {
1027 uLong headerId;
1028 uLong dataSize;
702 1029
1030 if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK)
1031 err=UNZ_ERRNO;
1032
1033 if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK)
1034 err=UNZ_ERRNO;
1035
1036 /* ZIP64 extra fields */
1037 if (headerId == 0x0001)
1038 {
1039 uLong uL;
1040
1041 if(file_info.uncompressed_size == (ZPOS64_T)(unsigned long)-1)
1042 {
1043 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
1044 err=UNZ_ERRNO;
1045 }
1046
1047 if(file_info.compressed_size == (ZPOS64_T)(unsigned long)-1)
1048 {
1049 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
1050 err=UNZ_ERRNO;
1051 }
1052
1053 if(file_info_internal.offset_curfile == (ZPOS64_T)(unsigned long)-1)
1054 {
1055 /* Relative Header offset */
1056 if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
1057 err=UNZ_ERRNO;
1058 }
1059
1060 if(file_info.disk_num_start == (unsigned long)-1)
1061 {
1062 /* Disk Start Number */
1063 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
1064 err=UNZ_ERRNO;
1065 }
1066
1067 }
1068 else
1069 {
1070 if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
1071 err=UNZ_ERRNO;
1072 }
1073
1074 acc += 2 + 2 + dataSize;
1075 }
1076 }
703 1077
704 if ((err==UNZ_OK) && (szComment!=NULL)) 1078 if ((err==UNZ_OK) && (szComment!=NULL))
705 { 1079 {
@@ -713,18 +1087,22 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
713 uSizeRead = commentBufferSize; 1087 uSizeRead = commentBufferSize;
714 1088
715 if (lSeek!=0) 1089 if (lSeek!=0)
716 if (ZSEEK(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) 1090 {
1091 if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
717 lSeek=0; 1092 lSeek=0;
718 else 1093 else
719 err=UNZ_ERRNO; 1094 err=UNZ_ERRNO;
1095 }
1096
720 if ((file_info.size_file_comment>0) && (commentBufferSize>0)) 1097 if ((file_info.size_file_comment>0) && (commentBufferSize>0))
721 if (ZREAD(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) 1098 if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
722 err=UNZ_ERRNO; 1099 err=UNZ_ERRNO;
723 lSeek+=file_info.size_file_comment - uSizeRead; 1100 lSeek+=file_info.size_file_comment - uSizeRead;
724 } 1101 }
725 else 1102 else
726 lSeek+=file_info.size_file_comment; 1103 lSeek+=file_info.size_file_comment;
727 1104
1105
728 if ((err==UNZ_OK) && (pfile_info!=NULL)) 1106 if ((err==UNZ_OK) && (pfile_info!=NULL))
729 *pfile_info=file_info; 1107 *pfile_info=file_info;
730 1108
@@ -741,41 +1119,70 @@ local int unzlocal_GetCurrentFileInfoInternal (file,
741 No preparation of the structure is needed 1119 No preparation of the structure is needed
742 return UNZ_OK if there is no problem. 1120 return UNZ_OK if there is no problem.
743*/ 1121*/
744extern int ZEXPORT unzGetCurrentFileInfo (file, 1122extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file,
745 pfile_info, 1123 unz_file_info64 * pfile_info,
746 szFileName, fileNameBufferSize, 1124 char * szFileName, uLong fileNameBufferSize,
747 extraField, extraFieldBufferSize, 1125 void *extraField, uLong extraFieldBufferSize,
748 szComment, commentBufferSize) 1126 char* szComment, uLong commentBufferSize)
749 unzFile file;
750 unz_file_info *pfile_info;
751 char *szFileName;
752 uLong fileNameBufferSize;
753 void *extraField;
754 uLong extraFieldBufferSize;
755 char *szComment;
756 uLong commentBufferSize;
757{ 1127{
758 return unzlocal_GetCurrentFileInfoInternal(file,pfile_info,NULL, 1128 return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL,
759 szFileName,fileNameBufferSize, 1129 szFileName,fileNameBufferSize,
760 extraField,extraFieldBufferSize, 1130 extraField,extraFieldBufferSize,
761 szComment,commentBufferSize); 1131 szComment,commentBufferSize);
762} 1132}
763 1133
1134extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
1135 unz_file_info * pfile_info,
1136 char * szFileName, uLong fileNameBufferSize,
1137 void *extraField, uLong extraFieldBufferSize,
1138 char* szComment, uLong commentBufferSize)
1139{
1140 int err;
1141 unz_file_info64 file_info64;
1142 err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL,
1143 szFileName,fileNameBufferSize,
1144 extraField,extraFieldBufferSize,
1145 szComment,commentBufferSize);
1146 if (err==UNZ_OK)
1147 {
1148 pfile_info->version = file_info64.version;
1149 pfile_info->version_needed = file_info64.version_needed;
1150 pfile_info->flag = file_info64.flag;
1151 pfile_info->compression_method = file_info64.compression_method;
1152 pfile_info->dosDate = file_info64.dosDate;
1153 pfile_info->crc = file_info64.crc;
1154
1155 pfile_info->size_filename = file_info64.size_filename;
1156 pfile_info->size_file_extra = file_info64.size_file_extra;
1157 pfile_info->size_file_comment = file_info64.size_file_comment;
1158
1159 pfile_info->disk_num_start = file_info64.disk_num_start;
1160 pfile_info->internal_fa = file_info64.internal_fa;
1161 pfile_info->external_fa = file_info64.external_fa;
1162
1163 pfile_info->tmu_date = file_info64.tmu_date,
1164
1165
1166 pfile_info->compressed_size = (uLong)file_info64.compressed_size;
1167 pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
1168
1169 }
1170 return err;
1171}
764/* 1172/*
765 Set the current file of the zipfile to the first file. 1173 Set the current file of the zipfile to the first file.
766 return UNZ_OK if there is no problem 1174 return UNZ_OK if there is no problem
767*/ 1175*/
768extern int ZEXPORT unzGoToFirstFile (file) 1176extern int ZEXPORT unzGoToFirstFile (unzFile file)
769 unzFile file;
770{ 1177{
771 int err=UNZ_OK; 1178 int err=UNZ_OK;
772 unz_s* s; 1179 unz64_s* s;
773 if (file==NULL) 1180 if (file==NULL)
774 return UNZ_PARAMERROR; 1181 return UNZ_PARAMERROR;
775 s=(unz_s*)file; 1182 s=(unz64_s*)file;
776 s->pos_in_central_dir=s->offset_central_dir; 1183 s->pos_in_central_dir=s->offset_central_dir;
777 s->num_file=0; 1184 s->num_file=0;
778 err=unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 1185 err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
779 &s->cur_file_info_internal, 1186 &s->cur_file_info_internal,
780 NULL,0,NULL,0,NULL,0); 1187 NULL,0,NULL,0,NULL,0);
781 s->current_file_ok = (err == UNZ_OK); 1188 s->current_file_ok = (err == UNZ_OK);
@@ -787,15 +1194,14 @@ extern int ZEXPORT unzGoToFirstFile (file)
787 return UNZ_OK if there is no problem 1194 return UNZ_OK if there is no problem
788 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. 1195 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
789*/ 1196*/
790extern int ZEXPORT unzGoToNextFile (file) 1197extern int ZEXPORT unzGoToNextFile (unzFile file)
791 unzFile file;
792{ 1198{
793 unz_s* s; 1199 unz64_s* s;
794 int err; 1200 int err;
795 1201
796 if (file==NULL) 1202 if (file==NULL)
797 return UNZ_PARAMERROR; 1203 return UNZ_PARAMERROR;
798 s=(unz_s*)file; 1204 s=(unz64_s*)file;
799 if (!s->current_file_ok) 1205 if (!s->current_file_ok)
800 return UNZ_END_OF_LIST_OF_FILE; 1206 return UNZ_END_OF_LIST_OF_FILE;
801 if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ 1207 if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */
@@ -805,7 +1211,7 @@ extern int ZEXPORT unzGoToNextFile (file)
805 s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + 1211 s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
806 s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; 1212 s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
807 s->num_file++; 1213 s->num_file++;
808 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 1214 err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
809 &s->cur_file_info_internal, 1215 &s->cur_file_info_internal,
810 NULL,0,NULL,0,NULL,0); 1216 NULL,0,NULL,0,NULL,0);
811 s->current_file_ok = (err == UNZ_OK); 1217 s->current_file_ok = (err == UNZ_OK);
@@ -821,21 +1227,18 @@ extern int ZEXPORT unzGoToNextFile (file)
821 UNZ_OK if the file is found. It becomes the current file. 1227 UNZ_OK if the file is found. It becomes the current file.
822 UNZ_END_OF_LIST_OF_FILE if the file is not found 1228 UNZ_END_OF_LIST_OF_FILE if the file is not found
823*/ 1229*/
824extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity) 1230extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
825 unzFile file;
826 const char *szFileName;
827 int iCaseSensitivity;
828{ 1231{
829 unz_s* s; 1232 unz64_s* s;
830 int err; 1233 int err;
831 1234
832 /* We remember the 'current' position in the file so that we can jump 1235 /* We remember the 'current' position in the file so that we can jump
833 * back there if we fail. 1236 * back there if we fail.
834 */ 1237 */
835 unz_file_info cur_file_infoSaved; 1238 unz_file_info64 cur_file_infoSaved;
836 unz_file_info_internal cur_file_info_internalSaved; 1239 unz_file_info64_internal cur_file_info_internalSaved;
837 uLong num_fileSaved; 1240 ZPOS64_T num_fileSaved;
838 uLong pos_in_central_dirSaved; 1241 ZPOS64_T pos_in_central_dirSaved;
839 1242
840 1243
841 if (file==NULL) 1244 if (file==NULL)
@@ -844,7 +1247,7 @@ extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
844 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) 1247 if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
845 return UNZ_PARAMERROR; 1248 return UNZ_PARAMERROR;
846 1249
847 s=(unz_s*)file; 1250 s=(unz64_s*)file;
848 if (!s->current_file_ok) 1251 if (!s->current_file_ok)
849 return UNZ_END_OF_LIST_OF_FILE; 1252 return UNZ_END_OF_LIST_OF_FILE;
850 1253
@@ -859,7 +1262,7 @@ extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
859 while (err == UNZ_OK) 1262 while (err == UNZ_OK)
860 { 1263 {
861 char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; 1264 char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
862 err = unzGetCurrentFileInfo(file,NULL, 1265 err = unzGetCurrentFileInfo64(file,NULL,
863 szCurrentFileName,sizeof(szCurrentFileName)-1, 1266 szCurrentFileName,sizeof(szCurrentFileName)-1,
864 NULL,0,NULL,0); 1267 NULL,0,NULL,0);
865 if (err == UNZ_OK) 1268 if (err == UNZ_OK)
@@ -895,20 +1298,18 @@ extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
895/* 1298/*
896typedef struct unz_file_pos_s 1299typedef struct unz_file_pos_s
897{ 1300{
898 uLong pos_in_zip_directory; // offset in file 1301 ZPOS64_T pos_in_zip_directory; // offset in file
899 uLong num_of_file; // # of file 1302 ZPOS64_T num_of_file; // # of file
900} unz_file_pos; 1303} unz_file_pos;
901*/ 1304*/
902 1305
903extern int ZEXPORT unzGetFilePos(file, file_pos) 1306extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos)
904 unzFile file;
905 unz_file_pos* file_pos;
906{ 1307{
907 unz_s* s; 1308 unz64_s* s;
908 1309
909 if (file==NULL || file_pos==NULL) 1310 if (file==NULL || file_pos==NULL)
910 return UNZ_PARAMERROR; 1311 return UNZ_PARAMERROR;
911 s=(unz_s*)file; 1312 s=(unz64_s*)file;
912 if (!s->current_file_ok) 1313 if (!s->current_file_ok)
913 return UNZ_END_OF_LIST_OF_FILE; 1314 return UNZ_END_OF_LIST_OF_FILE;
914 1315
@@ -918,23 +1319,35 @@ extern int ZEXPORT unzGetFilePos(file, file_pos)
918 return UNZ_OK; 1319 return UNZ_OK;
919} 1320}
920 1321
921extern int ZEXPORT unzGoToFilePos(file, file_pos) 1322extern int ZEXPORT unzGetFilePos(
922 unzFile file; 1323 unzFile file,
923 unz_file_pos* file_pos; 1324 unz_file_pos* file_pos)
1325{
1326 unz64_file_pos file_pos64;
1327 int err = unzGetFilePos64(file,&file_pos64);
1328 if (err==UNZ_OK)
1329 {
1330 file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
1331 file_pos->num_of_file = (uLong)file_pos64.num_of_file;
1332 }
1333 return err;
1334}
1335
1336extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos)
924{ 1337{
925 unz_s* s; 1338 unz64_s* s;
926 int err; 1339 int err;
927 1340
928 if (file==NULL || file_pos==NULL) 1341 if (file==NULL || file_pos==NULL)
929 return UNZ_PARAMERROR; 1342 return UNZ_PARAMERROR;
930 s=(unz_s*)file; 1343 s=(unz64_s*)file;
931 1344
932 /* jump to the right spot */ 1345 /* jump to the right spot */
933 s->pos_in_central_dir = file_pos->pos_in_zip_directory; 1346 s->pos_in_central_dir = file_pos->pos_in_zip_directory;
934 s->num_file = file_pos->num_of_file; 1347 s->num_file = file_pos->num_of_file;
935 1348
936 /* set the current file */ 1349 /* set the current file */
937 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 1350 err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
938 &s->cur_file_info_internal, 1351 &s->cur_file_info_internal,
939 NULL,0,NULL,0,NULL,0); 1352 NULL,0,NULL,0,NULL,0);
940 /* return results */ 1353 /* return results */
@@ -942,6 +1355,19 @@ extern int ZEXPORT unzGoToFilePos(file, file_pos)
942 return err; 1355 return err;
943} 1356}
944 1357
1358extern int ZEXPORT unzGoToFilePos(
1359 unzFile file,
1360 unz_file_pos* file_pos)
1361{
1362 unz64_file_pos file_pos64;
1363 if (file_pos == NULL)
1364 return UNZ_PARAMERROR;
1365
1366 file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
1367 file_pos64.num_of_file = file_pos->num_of_file;
1368 return unzGoToFilePos64(file,&file_pos64);
1369}
1370
945/* 1371/*
946// Unzip Helper Functions - should be here? 1372// Unzip Helper Functions - should be here?
947/////////////////////////////////////////// 1373///////////////////////////////////////////
@@ -954,13 +1380,9 @@ extern int ZEXPORT unzGoToFilePos(file, file_pos)
954 store in *piSizeVar the size of extra info in local header 1380 store in *piSizeVar the size of extra info in local header
955 (filename and size of extra field data) 1381 (filename and size of extra field data)
956*/ 1382*/
957local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar, 1383local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar,
958 poffset_local_extrafield, 1384 ZPOS64_T * poffset_local_extrafield,
959 psize_local_extrafield) 1385 uInt * psize_local_extrafield)
960 unz_s* s;
961 uInt* piSizeVar;
962 uLong *poffset_local_extrafield;
963 uInt *psize_local_extrafield;
964{ 1386{
965 uLong uMagic,uData,uFlags; 1387 uLong uMagic,uData,uFlags;
966 uLong size_filename; 1388 uLong size_filename;
@@ -971,65 +1393,66 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
971 *poffset_local_extrafield = 0; 1393 *poffset_local_extrafield = 0;
972 *psize_local_extrafield = 0; 1394 *psize_local_extrafield = 0;
973 1395
974 if (ZSEEK(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + 1396 if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
975 s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) 1397 s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
976 return UNZ_ERRNO; 1398 return UNZ_ERRNO;
977 1399
978 1400
979 if (err==UNZ_OK) 1401 if (err==UNZ_OK)
980 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) 1402 {
1403 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
981 err=UNZ_ERRNO; 1404 err=UNZ_ERRNO;
982 else if (uMagic!=0x04034b50) 1405 else if (uMagic!=0x04034b50)
983 err=UNZ_BADZIPFILE; 1406 err=UNZ_BADZIPFILE;
1407 }
984 1408
985 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) 1409 if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
986 err=UNZ_ERRNO; 1410 err=UNZ_ERRNO;
987/* 1411/*
988 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) 1412 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
989 err=UNZ_BADZIPFILE; 1413 err=UNZ_BADZIPFILE;
990*/ 1414*/
991 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) 1415 if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
992 err=UNZ_ERRNO; 1416 err=UNZ_ERRNO;
993 1417
994 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) 1418 if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
995 err=UNZ_ERRNO; 1419 err=UNZ_ERRNO;
996 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) 1420 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
997 err=UNZ_BADZIPFILE; 1421 err=UNZ_BADZIPFILE;
998 1422
999 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && 1423 if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
1424/* #ifdef HAVE_BZIP2 */
1425 (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
1426/* #endif */
1000 (s->cur_file_info.compression_method!=Z_DEFLATED)) 1427 (s->cur_file_info.compression_method!=Z_DEFLATED))
1001 err=UNZ_BADZIPFILE; 1428 err=UNZ_BADZIPFILE;
1002 1429
1003 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ 1430 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
1004 err=UNZ_ERRNO; 1431 err=UNZ_ERRNO;
1005 1432
1006 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ 1433 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
1007 err=UNZ_ERRNO; 1434 err=UNZ_ERRNO;
1008 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && 1435 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0))
1009 ((uFlags & 8)==0))
1010 err=UNZ_BADZIPFILE; 1436 err=UNZ_BADZIPFILE;
1011 1437
1012 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ 1438 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
1013 err=UNZ_ERRNO; 1439 err=UNZ_ERRNO;
1014 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && 1440 else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0))
1015 ((uFlags & 8)==0))
1016 err=UNZ_BADZIPFILE; 1441 err=UNZ_BADZIPFILE;
1017 1442
1018 if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ 1443 if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
1019 err=UNZ_ERRNO; 1444 err=UNZ_ERRNO;
1020 else if ((err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && 1445 else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0))
1021 ((uFlags & 8)==0))
1022 err=UNZ_BADZIPFILE; 1446 err=UNZ_BADZIPFILE;
1023 1447
1024 1448 if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
1025 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
1026 err=UNZ_ERRNO; 1449 err=UNZ_ERRNO;
1027 else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) 1450 else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
1028 err=UNZ_BADZIPFILE; 1451 err=UNZ_BADZIPFILE;
1029 1452
1030 *piSizeVar += (uInt)size_filename; 1453 *piSizeVar += (uInt)size_filename;
1031 1454
1032 if (unzlocal_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) 1455 if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
1033 err=UNZ_ERRNO; 1456 err=UNZ_ERRNO;
1034 *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + 1457 *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
1035 SIZEZIPLOCALHEADER + size_filename; 1458 SIZEZIPLOCALHEADER + size_filename;
@@ -1044,18 +1467,14 @@ local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
1044 Open for reading data the current file in the zipfile. 1467 Open for reading data the current file in the zipfile.
1045 If there is no error and the file is opened, the return value is UNZ_OK. 1468 If there is no error and the file is opened, the return value is UNZ_OK.
1046*/ 1469*/
1047extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password) 1470extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
1048 unzFile file; 1471 int* level, int raw, const char* password)
1049 int* method;
1050 int* level;
1051 int raw;
1052 const char* password;
1053{ 1472{
1054 int err=UNZ_OK; 1473 int err=UNZ_OK;
1055 uInt iSizeVar; 1474 uInt iSizeVar;
1056 unz_s* s; 1475 unz64_s* s;
1057 file_in_zip_read_info_s* pfile_in_zip_read_info; 1476 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1058 uLong offset_local_extrafield; /* offset of the local extra field */ 1477 ZPOS64_T offset_local_extrafield; /* offset of the local extra field */
1059 uInt size_local_extrafield; /* size of the local extra field */ 1478 uInt size_local_extrafield; /* size of the local extra field */
1060# ifndef NOUNCRYPT 1479# ifndef NOUNCRYPT
1061 char source[12]; 1480 char source[12];
@@ -1066,19 +1485,17 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1066 1485
1067 if (file==NULL) 1486 if (file==NULL)
1068 return UNZ_PARAMERROR; 1487 return UNZ_PARAMERROR;
1069 s=(unz_s*)file; 1488 s=(unz64_s*)file;
1070 if (!s->current_file_ok) 1489 if (!s->current_file_ok)
1071 return UNZ_PARAMERROR; 1490 return UNZ_PARAMERROR;
1072 1491
1073 if (s->pfile_in_zip_read != NULL) 1492 if (s->pfile_in_zip_read != NULL)
1074 unzCloseCurrentFile(file); 1493 unzCloseCurrentFile(file);
1075 1494
1076 if (unzlocal_CheckCurrentFileCoherencyHeader(s,&iSizeVar, 1495 if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1077 &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
1078 return UNZ_BADZIPFILE; 1496 return UNZ_BADZIPFILE;
1079 1497
1080 pfile_in_zip_read_info = (file_in_zip_read_info_s*) 1498 pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s));
1081 ALLOC(sizeof(file_in_zip_read_info_s));
1082 if (pfile_in_zip_read_info==NULL) 1499 if (pfile_in_zip_read_info==NULL)
1083 return UNZ_INTERNALERROR; 1500 return UNZ_INTERNALERROR;
1084 1501
@@ -1111,31 +1528,60 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1111 } 1528 }
1112 1529
1113 if ((s->cur_file_info.compression_method!=0) && 1530 if ((s->cur_file_info.compression_method!=0) &&
1531/* #ifdef HAVE_BZIP2 */
1532 (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
1533/* #endif */
1114 (s->cur_file_info.compression_method!=Z_DEFLATED)) 1534 (s->cur_file_info.compression_method!=Z_DEFLATED))
1535
1115 err=UNZ_BADZIPFILE; 1536 err=UNZ_BADZIPFILE;
1116 1537
1117 pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; 1538 pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
1118 pfile_in_zip_read_info->crc32=0; 1539 pfile_in_zip_read_info->crc32=0;
1119 pfile_in_zip_read_info->compression_method = 1540 pfile_in_zip_read_info->total_out_64=0;
1120 s->cur_file_info.compression_method; 1541 pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method;
1121 pfile_in_zip_read_info->filestream=s->filestream; 1542 pfile_in_zip_read_info->filestream=s->filestream;
1122 pfile_in_zip_read_info->z_filefunc=s->z_filefunc; 1543 pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
1123 pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; 1544 pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
1124 1545
1125 pfile_in_zip_read_info->stream.total_out = 0; 1546 pfile_in_zip_read_info->stream.total_out = 0;
1126 1547
1127 if ((s->cur_file_info.compression_method==Z_DEFLATED) && 1548 if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw))
1128 (!raw))
1129 { 1549 {
1550#ifdef HAVE_BZIP2
1551 pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0;
1552 pfile_in_zip_read_info->bstream.bzfree = (free_func)0;
1553 pfile_in_zip_read_info->bstream.opaque = (voidpf)0;
1554 pfile_in_zip_read_info->bstream.state = (voidpf)0;
1555
1130 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; 1556 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1131 pfile_in_zip_read_info->stream.zfree = (free_func)0; 1557 pfile_in_zip_read_info->stream.zfree = (free_func)0;
1132 pfile_in_zip_read_info->stream.opaque = (voidpf)0; 1558 pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1133 pfile_in_zip_read_info->stream.next_in = (voidpf)0; 1559 pfile_in_zip_read_info->stream.next_in = (voidpf)0;
1134 pfile_in_zip_read_info->stream.avail_in = 0; 1560 pfile_in_zip_read_info->stream.avail_in = 0;
1135 1561
1562 err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
1563 if (err == Z_OK)
1564 pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
1565 else
1566 {
1567 TRYFREE(pfile_in_zip_read_info);
1568 return err;
1569 }
1570#else
1571 pfile_in_zip_read_info->raw=1;
1572#endif
1573 }
1574 else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw))
1575 {
1576 pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
1577 pfile_in_zip_read_info->stream.zfree = (free_func)0;
1578 pfile_in_zip_read_info->stream.opaque = (voidpf)0;
1579 pfile_in_zip_read_info->stream.next_in = 0;
1580 pfile_in_zip_read_info->stream.avail_in = 0;
1581
1136 err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); 1582 err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
1137 if (err == Z_OK) 1583 if (err == Z_OK)
1138 pfile_in_zip_read_info->stream_initialised=1; 1584 pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
1139 else 1585 else
1140 { 1586 {
1141 TRYFREE(pfile_in_zip_read_info); 1587 TRYFREE(pfile_in_zip_read_info);
@@ -1162,8 +1608,7 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1162 pfile_in_zip_read_info->stream.avail_in = (uInt)0; 1608 pfile_in_zip_read_info->stream.avail_in = (uInt)0;
1163 1609
1164 s->pfile_in_zip_read = pfile_in_zip_read_info; 1610 s->pfile_in_zip_read = pfile_in_zip_read_info;
1165 1611 s->encrypted = 0;
1166 s->encrypted = 0;
1167 1612
1168# ifndef NOUNCRYPT 1613# ifndef NOUNCRYPT
1169 if (password != NULL) 1614 if (password != NULL)
@@ -1171,12 +1616,12 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1171 int i; 1616 int i;
1172 s->pcrc_32_tab = get_crc_table(); 1617 s->pcrc_32_tab = get_crc_table();
1173 init_keys(password,s->keys,s->pcrc_32_tab); 1618 init_keys(password,s->keys,s->pcrc_32_tab);
1174 if (ZSEEK(s->z_filefunc, s->filestream, 1619 if (ZSEEK64(s->z_filefunc, s->filestream,
1175 s->pfile_in_zip_read->pos_in_zipfile + 1620 s->pfile_in_zip_read->pos_in_zipfile +
1176 s->pfile_in_zip_read->byte_before_the_zipfile, 1621 s->pfile_in_zip_read->byte_before_the_zipfile,
1177 SEEK_SET)!=0) 1622 SEEK_SET)!=0)
1178 return UNZ_INTERNALERROR; 1623 return UNZ_INTERNALERROR;
1179 if(ZREAD(s->z_filefunc, s->filestream,source, 12)<12) 1624 if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12)
1180 return UNZ_INTERNALERROR; 1625 return UNZ_INTERNALERROR;
1181 1626
1182 for (i = 0; i<12; i++) 1627 for (i = 0; i<12; i++)
@@ -1191,28 +1636,39 @@ extern int ZEXPORT unzOpenCurrentFile3 (file, method, level, raw, password)
1191 return UNZ_OK; 1636 return UNZ_OK;
1192} 1637}
1193 1638
1194extern int ZEXPORT unzOpenCurrentFile (file) 1639extern int ZEXPORT unzOpenCurrentFile (unzFile file)
1195 unzFile file;
1196{ 1640{
1197 return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); 1641 return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
1198} 1642}
1199 1643
1200extern int ZEXPORT unzOpenCurrentFilePassword (file, password) 1644extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password)
1201 unzFile file;
1202 const char* password;
1203{ 1645{
1204 return unzOpenCurrentFile3(file, NULL, NULL, 0, password); 1646 return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
1205} 1647}
1206 1648
1207extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw) 1649extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw)
1208 unzFile file;
1209 int* method;
1210 int* level;
1211 int raw;
1212{ 1650{
1213 return unzOpenCurrentFile3(file, method, level, raw, NULL); 1651 return unzOpenCurrentFile3(file, method, level, raw, NULL);
1214} 1652}
1215 1653
1654/** Addition for GDAL : START */
1655
1656extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file)
1657{
1658 unz64_s* s;
1659 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1660 s=(unz64_s*)file;
1661 if (file==NULL)
1662 return 0; //UNZ_PARAMERROR;
1663 pfile_in_zip_read_info=s->pfile_in_zip_read;
1664 if (pfile_in_zip_read_info==NULL)
1665 return 0; //UNZ_PARAMERROR;
1666 return pfile_in_zip_read_info->pos_in_zipfile +
1667 pfile_in_zip_read_info->byte_before_the_zipfile;
1668}
1669
1670/** Addition for GDAL : END */
1671
1216/* 1672/*
1217 Read bytes from the current file. 1673 Read bytes from the current file.
1218 buf contain buffer where data must be copied 1674 buf contain buffer where data must be copied
@@ -1223,18 +1679,15 @@ extern int ZEXPORT unzOpenCurrentFile2 (file,method,level,raw)
1223 return <0 with error code if there is an error 1679 return <0 with error code if there is an error
1224 (UNZ_ERRNO for IO error, or zLib error for uncompress error) 1680 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
1225*/ 1681*/
1226extern int ZEXPORT unzReadCurrentFile (file, buf, len) 1682extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
1227 unzFile file;
1228 voidp buf;
1229 unsigned len;
1230{ 1683{
1231 int err=UNZ_OK; 1684 int err=UNZ_OK;
1232 uInt iRead = 0; 1685 uInt iRead = 0;
1233 unz_s* s; 1686 unz64_s* s;
1234 file_in_zip_read_info_s* pfile_in_zip_read_info; 1687 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1235 if (file==NULL) 1688 if (file==NULL)
1236 return UNZ_PARAMERROR; 1689 return UNZ_PARAMERROR;
1237 s=(unz_s*)file; 1690 s=(unz64_s*)file;
1238 pfile_in_zip_read_info=s->pfile_in_zip_read; 1691 pfile_in_zip_read_info=s->pfile_in_zip_read;
1239 1692
1240 if (pfile_in_zip_read_info==NULL) 1693 if (pfile_in_zip_read_info==NULL)
@@ -1272,13 +1725,13 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1272 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed; 1725 uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
1273 if (uReadThis == 0) 1726 if (uReadThis == 0)
1274 return UNZ_EOF; 1727 return UNZ_EOF;
1275 if (ZSEEK(pfile_in_zip_read_info->z_filefunc, 1728 if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
1276 pfile_in_zip_read_info->filestream, 1729 pfile_in_zip_read_info->filestream,
1277 pfile_in_zip_read_info->pos_in_zipfile + 1730 pfile_in_zip_read_info->pos_in_zipfile +
1278 pfile_in_zip_read_info->byte_before_the_zipfile, 1731 pfile_in_zip_read_info->byte_before_the_zipfile,
1279 ZLIB_FILEFUNC_SEEK_SET)!=0) 1732 ZLIB_FILEFUNC_SEEK_SET)!=0)
1280 return UNZ_ERRNO; 1733 return UNZ_ERRNO;
1281 if (ZREAD(pfile_in_zip_read_info->z_filefunc, 1734 if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
1282 pfile_in_zip_read_info->filestream, 1735 pfile_in_zip_read_info->filestream,
1283 pfile_in_zip_read_info->read_buffer, 1736 pfile_in_zip_read_info->read_buffer,
1284 uReadThis)!=uReadThis) 1737 uReadThis)!=uReadThis)
@@ -1324,6 +1777,8 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1324 *(pfile_in_zip_read_info->stream.next_out+i) = 1777 *(pfile_in_zip_read_info->stream.next_out+i) =
1325 *(pfile_in_zip_read_info->stream.next_in+i); 1778 *(pfile_in_zip_read_info->stream.next_in+i);
1326 1779
1780 pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy;
1781
1327 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, 1782 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
1328 pfile_in_zip_read_info->stream.next_out, 1783 pfile_in_zip_read_info->stream.next_out,
1329 uDoCopy); 1784 uDoCopy);
@@ -1335,11 +1790,54 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1335 pfile_in_zip_read_info->stream.total_out += uDoCopy; 1790 pfile_in_zip_read_info->stream.total_out += uDoCopy;
1336 iRead += uDoCopy; 1791 iRead += uDoCopy;
1337 } 1792 }
1338 else 1793 else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED)
1339 { 1794 {
1795#ifdef HAVE_BZIP2
1340 uLong uTotalOutBefore,uTotalOutAfter; 1796 uLong uTotalOutBefore,uTotalOutAfter;
1341 const Bytef *bufBefore; 1797 const Bytef *bufBefore;
1342 uLong uOutThis; 1798 uLong uOutThis;
1799
1800 pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in;
1801 pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in;
1802 pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in;
1803 pfile_in_zip_read_info->bstream.total_in_hi32 = 0;
1804 pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out;
1805 pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out;
1806 pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out;
1807 pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
1808
1809 uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32;
1810 bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out;
1811
1812 err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
1813
1814 uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32;
1815 uOutThis = uTotalOutAfter-uTotalOutBefore;
1816
1817 pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
1818
1819 pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis));
1820 pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
1821 iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
1822
1823 pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in;
1824 pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in;
1825 pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32;
1826 pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out;
1827 pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
1828 pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
1829
1830 if (err==BZ_STREAM_END)
1831 return (iRead==0) ? UNZ_EOF : iRead;
1832 if (err!=BZ_OK)
1833 break;
1834#endif
1835 } // end Z_BZIP2ED
1836 else
1837 {
1838 ZPOS64_T uTotalOutBefore,uTotalOutAfter;
1839 const Bytef *bufBefore;
1840 ZPOS64_T uOutThis;
1343 int flush=Z_SYNC_FLUSH; 1841 int flush=Z_SYNC_FLUSH;
1344 1842
1345 uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; 1843 uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
@@ -1359,6 +1857,8 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1359 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; 1857 uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
1360 uOutThis = uTotalOutAfter-uTotalOutBefore; 1858 uOutThis = uTotalOutAfter-uTotalOutBefore;
1361 1859
1860 pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
1861
1362 pfile_in_zip_read_info->crc32 = 1862 pfile_in_zip_read_info->crc32 =
1363 crc32(pfile_in_zip_read_info->crc32,bufBefore, 1863 crc32(pfile_in_zip_read_info->crc32,bufBefore,
1364 (uInt)(uOutThis)); 1864 (uInt)(uOutThis));
@@ -1384,14 +1884,13 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len)
1384/* 1884/*
1385 Give the current position in uncompressed data 1885 Give the current position in uncompressed data
1386*/ 1886*/
1387extern z_off_t ZEXPORT unztell (file) 1887extern z_off_t ZEXPORT unztell (unzFile file)
1388 unzFile file;
1389{ 1888{
1390 unz_s* s; 1889 unz64_s* s;
1391 file_in_zip_read_info_s* pfile_in_zip_read_info; 1890 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1392 if (file==NULL) 1891 if (file==NULL)
1393 return UNZ_PARAMERROR; 1892 return UNZ_PARAMERROR;
1394 s=(unz_s*)file; 1893 s=(unz64_s*)file;
1395 pfile_in_zip_read_info=s->pfile_in_zip_read; 1894 pfile_in_zip_read_info=s->pfile_in_zip_read;
1396 1895
1397 if (pfile_in_zip_read_info==NULL) 1896 if (pfile_in_zip_read_info==NULL)
@@ -1400,18 +1899,33 @@ extern z_off_t ZEXPORT unztell (file)
1400 return (z_off_t)pfile_in_zip_read_info->stream.total_out; 1899 return (z_off_t)pfile_in_zip_read_info->stream.total_out;
1401} 1900}
1402 1901
1902extern ZPOS64_T ZEXPORT unztell64 (unzFile file)
1903{
1904
1905 unz64_s* s;
1906 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1907 if (file==NULL)
1908 return (ZPOS64_T)-1;
1909 s=(unz64_s*)file;
1910 pfile_in_zip_read_info=s->pfile_in_zip_read;
1911
1912 if (pfile_in_zip_read_info==NULL)
1913 return (ZPOS64_T)-1;
1914
1915 return pfile_in_zip_read_info->total_out_64;
1916}
1917
1403 1918
1404/* 1919/*
1405 return 1 if the end of file was reached, 0 elsewhere 1920 return 1 if the end of file was reached, 0 elsewhere
1406*/ 1921*/
1407extern int ZEXPORT unzeof (file) 1922extern int ZEXPORT unzeof (unzFile file)
1408 unzFile file;
1409{ 1923{
1410 unz_s* s; 1924 unz64_s* s;
1411 file_in_zip_read_info_s* pfile_in_zip_read_info; 1925 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1412 if (file==NULL) 1926 if (file==NULL)
1413 return UNZ_PARAMERROR; 1927 return UNZ_PARAMERROR;
1414 s=(unz_s*)file; 1928 s=(unz64_s*)file;
1415 pfile_in_zip_read_info=s->pfile_in_zip_read; 1929 pfile_in_zip_read_info=s->pfile_in_zip_read;
1416 1930
1417 if (pfile_in_zip_read_info==NULL) 1931 if (pfile_in_zip_read_info==NULL)
@@ -1426,9 +1940,9 @@ extern int ZEXPORT unzeof (file)
1426 1940
1427 1941
1428/* 1942/*
1429 Read extra field from the current file (opened by unzOpenCurrentFile) 1943Read extra field from the current file (opened by unzOpenCurrentFile)
1430 This is the local-header version of the extra field (sometimes, there is 1944This is the local-header version of the extra field (sometimes, there is
1431 more info in the local-header version than in the central-header) 1945more info in the local-header version than in the central-header)
1432 1946
1433 if buf==NULL, it return the size of the local extra field that can be read 1947 if buf==NULL, it return the size of the local extra field that can be read
1434 1948
@@ -1437,19 +1951,16 @@ extern int ZEXPORT unzeof (file)
1437 the return value is the number of bytes copied in buf, or (if <0) 1951 the return value is the number of bytes copied in buf, or (if <0)
1438 the error code 1952 the error code
1439*/ 1953*/
1440extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) 1954extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
1441 unzFile file;
1442 voidp buf;
1443 unsigned len;
1444{ 1955{
1445 unz_s* s; 1956 unz64_s* s;
1446 file_in_zip_read_info_s* pfile_in_zip_read_info; 1957 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1447 uInt read_now; 1958 uInt read_now;
1448 uLong size_to_read; 1959 ZPOS64_T size_to_read;
1449 1960
1450 if (file==NULL) 1961 if (file==NULL)
1451 return UNZ_PARAMERROR; 1962 return UNZ_PARAMERROR;
1452 s=(unz_s*)file; 1963 s=(unz64_s*)file;
1453 pfile_in_zip_read_info=s->pfile_in_zip_read; 1964 pfile_in_zip_read_info=s->pfile_in_zip_read;
1454 1965
1455 if (pfile_in_zip_read_info==NULL) 1966 if (pfile_in_zip_read_info==NULL)
@@ -1469,14 +1980,14 @@ extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
1469 if (read_now==0) 1980 if (read_now==0)
1470 return 0; 1981 return 0;
1471 1982
1472 if (ZSEEK(pfile_in_zip_read_info->z_filefunc, 1983 if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
1473 pfile_in_zip_read_info->filestream, 1984 pfile_in_zip_read_info->filestream,
1474 pfile_in_zip_read_info->offset_local_extrafield + 1985 pfile_in_zip_read_info->offset_local_extrafield +
1475 pfile_in_zip_read_info->pos_local_extrafield, 1986 pfile_in_zip_read_info->pos_local_extrafield,
1476 ZLIB_FILEFUNC_SEEK_SET)!=0) 1987 ZLIB_FILEFUNC_SEEK_SET)!=0)
1477 return UNZ_ERRNO; 1988 return UNZ_ERRNO;
1478 1989
1479 if (ZREAD(pfile_in_zip_read_info->z_filefunc, 1990 if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
1480 pfile_in_zip_read_info->filestream, 1991 pfile_in_zip_read_info->filestream,
1481 buf,read_now)!=read_now) 1992 buf,read_now)!=read_now)
1482 return UNZ_ERRNO; 1993 return UNZ_ERRNO;
@@ -1488,16 +1999,15 @@ extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
1488 Close the file in zip opened with unzipOpenCurrentFile 1999 Close the file in zip opened with unzipOpenCurrentFile
1489 Return UNZ_CRCERROR if all the file was read but the CRC is not good 2000 Return UNZ_CRCERROR if all the file was read but the CRC is not good
1490*/ 2001*/
1491extern int ZEXPORT unzCloseCurrentFile (file) 2002extern int ZEXPORT unzCloseCurrentFile (unzFile file)
1492 unzFile file;
1493{ 2003{
1494 int err=UNZ_OK; 2004 int err=UNZ_OK;
1495 2005
1496 unz_s* s; 2006 unz64_s* s;
1497 file_in_zip_read_info_s* pfile_in_zip_read_info; 2007 file_in_zip64_read_info_s* pfile_in_zip_read_info;
1498 if (file==NULL) 2008 if (file==NULL)
1499 return UNZ_PARAMERROR; 2009 return UNZ_PARAMERROR;
1500 s=(unz_s*)file; 2010 s=(unz64_s*)file;
1501 pfile_in_zip_read_info=s->pfile_in_zip_read; 2011 pfile_in_zip_read_info=s->pfile_in_zip_read;
1502 2012
1503 if (pfile_in_zip_read_info==NULL) 2013 if (pfile_in_zip_read_info==NULL)
@@ -1514,8 +2024,13 @@ extern int ZEXPORT unzCloseCurrentFile (file)
1514 2024
1515 TRYFREE(pfile_in_zip_read_info->read_buffer); 2025 TRYFREE(pfile_in_zip_read_info->read_buffer);
1516 pfile_in_zip_read_info->read_buffer = NULL; 2026 pfile_in_zip_read_info->read_buffer = NULL;
1517 if (pfile_in_zip_read_info->stream_initialised) 2027 if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
1518 inflateEnd(&pfile_in_zip_read_info->stream); 2028 inflateEnd(&pfile_in_zip_read_info->stream);
2029#ifdef HAVE_BZIP2
2030 else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
2031 BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
2032#endif
2033
1519 2034
1520 pfile_in_zip_read_info->stream_initialised = 0; 2035 pfile_in_zip_read_info->stream_initialised = 0;
1521 TRYFREE(pfile_in_zip_read_info); 2036 TRYFREE(pfile_in_zip_read_info);
@@ -1531,29 +2046,25 @@ extern int ZEXPORT unzCloseCurrentFile (file)
1531 uSizeBuf is the size of the szComment buffer. 2046 uSizeBuf is the size of the szComment buffer.
1532 return the number of byte copied or an error code <0 2047 return the number of byte copied or an error code <0
1533*/ 2048*/
1534extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) 2049extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf)
1535 unzFile file;
1536 char *szComment;
1537 uLong uSizeBuf;
1538{ 2050{
1539 int err=UNZ_OK; 2051 unz64_s* s;
1540 unz_s* s;
1541 uLong uReadThis ; 2052 uLong uReadThis ;
1542 if (file==NULL) 2053 if (file==NULL)
1543 return UNZ_PARAMERROR; 2054 return (uLong)UNZ_PARAMERROR;
1544 s=(unz_s*)file; 2055 s=(unz64_s*)file;
1545 2056
1546 uReadThis = uSizeBuf; 2057 uReadThis = uSizeBuf;
1547 if (uReadThis>s->gi.size_comment) 2058 if (uReadThis>s->gi.size_comment)
1548 uReadThis = s->gi.size_comment; 2059 uReadThis = s->gi.size_comment;
1549 2060
1550 if (ZSEEK(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) 2061 if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
1551 return UNZ_ERRNO; 2062 return UNZ_ERRNO;
1552 2063
1553 if (uReadThis>0) 2064 if (uReadThis>0)
1554 { 2065 {
1555 *szComment='\0'; 2066 *szComment='\0';
1556 if (ZREAD(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) 2067 if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
1557 return UNZ_ERRNO; 2068 return UNZ_ERRNO;
1558 } 2069 }
1559 2070
@@ -1563,14 +2074,13 @@ extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
1563} 2074}
1564 2075
1565/* Additions by RX '2004 */ 2076/* Additions by RX '2004 */
1566extern uLong ZEXPORT unzGetOffset (file) 2077extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
1567 unzFile file;
1568{ 2078{
1569 unz_s* s; 2079 unz64_s* s;
1570 2080
1571 if (file==NULL) 2081 if (file==NULL)
1572 return UNZ_PARAMERROR; 2082 return 0; //UNZ_PARAMERROR;
1573 s=(unz_s*)file; 2083 s=(unz64_s*)file;
1574 if (!s->current_file_ok) 2084 if (!s->current_file_ok)
1575 return 0; 2085 return 0;
1576 if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) 2086 if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
@@ -1579,22 +2089,35 @@ extern uLong ZEXPORT unzGetOffset (file)
1579 return s->pos_in_central_dir; 2089 return s->pos_in_central_dir;
1580} 2090}
1581 2091
1582extern int ZEXPORT unzSetOffset (file, pos) 2092extern uLong ZEXPORT unzGetOffset (unzFile file)
1583 unzFile file; 2093{
1584 uLong pos; 2094 ZPOS64_T offset64;
2095
2096 if (file==NULL)
2097 return 0; //UNZ_PARAMERROR;
2098 offset64 = unzGetOffset64(file);
2099 return (uLong)offset64;
2100}
2101
2102extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
1585{ 2103{
1586 unz_s* s; 2104 unz64_s* s;
1587 int err; 2105 int err;
1588 2106
1589 if (file==NULL) 2107 if (file==NULL)
1590 return UNZ_PARAMERROR; 2108 return UNZ_PARAMERROR;
1591 s=(unz_s*)file; 2109 s=(unz64_s*)file;
1592 2110
1593 s->pos_in_central_dir = pos; 2111 s->pos_in_central_dir = pos;
1594 s->num_file = s->gi.number_entry; /* hack */ 2112 s->num_file = s->gi.number_entry; /* hack */
1595 err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, 2113 err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
1596 &s->cur_file_info_internal, 2114 &s->cur_file_info_internal,
1597 NULL,0,NULL,0,NULL,0); 2115 NULL,0,NULL,0,NULL,0);
1598 s->current_file_ok = (err == UNZ_OK); 2116 s->current_file_ok = (err == UNZ_OK);
1599 return err; 2117 return err;
1600} 2118}
2119
2120extern int ZEXPORT unzSetOffset (unzFile file, uLong pos)
2121{
2122 return unzSetOffset64(file,pos);
2123}