unzip.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244
  1. /* unzip.c -- IO for uncompress .zip files using zlib
  2. Version 1.1, February 14h, 2010
  3. part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
  4. Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
  5. Modifications of Unzip for Zip64
  6. Copyright (C) 2007-2008 Even Rouault
  7. Modifications for Zip64 support on both zip and unzip
  8. Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
  9. For more info read MiniZip_info.txt
  10. ------------------------------------------------------------------------------------
  11. Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of
  12. compatibility with older software. The following is from the original crypt.c.
  13. Code woven in by Terry Thorsen 1/2003.
  14. Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
  15. See the accompanying file LICENSE, version 2000-Apr-09 or later
  16. (the contents of which are also included in zip.h) for terms of use.
  17. If, for some reason, all these files are missing, the Info-ZIP license
  18. also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
  19. crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h]
  20. The encryption/decryption parts of this source code (as opposed to the
  21. non-echoing password parts) were originally written in Europe. The
  22. whole source package can be freely distributed, including from the USA.
  23. (Prior to January 2000, re-export from the US was a violation of US law.)
  24. This encryption code is a direct transcription of the algorithm from
  25. Roger Schlafly, described by Phil Katz in the file appnote.txt. This
  26. file (appnote.txt) is distributed with the PKZIP program (even in the
  27. version without encryption capabilities).
  28. ------------------------------------------------------------------------------------
  29. Changes in unzip.c
  30. 2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos
  31. 2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz*
  32. 2007-2008 - Even Rouault - Remove old C style function prototypes
  33. 2007-2008 - Even Rouault - Add unzip support for ZIP64
  34. Copyright (C) 2007-2008 Even Rouault
  35. Oct-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).
  36. Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G
  37. should only read the compressed/uncompressed size from the Zip64 format if
  38. the size from normal header was 0xFFFFFFFF
  39. Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant
  40. Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required)
  41. Patch created by Daniel Borca
  42. Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
  43. Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson
  44. */
  45. #include <stdio.h>
  46. #include <stdlib.h>
  47. #include <string.h>
  48. #ifndef NOUNCRYPT
  49. #define NOUNCRYPT
  50. #endif
  51. #include "zlib.h"
  52. #include "unzip.h"
  53. #ifdef STDC
  54. # include <stddef.h>
  55. # include <string.h>
  56. # include <stdlib.h>
  57. #endif
  58. #ifdef NO_ERRNO_H
  59. extern int errno;
  60. #else
  61. # include <errno.h>
  62. #endif
  63. #ifndef local
  64. # define local static
  65. #endif
  66. /* compile with -Dlocal if your debugger can't find static symbols */
  67. #ifndef CASESENSITIVITYDEFAULT_NO
  68. # if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES)
  69. # define CASESENSITIVITYDEFAULT_NO
  70. # endif
  71. #endif
  72. #ifndef UNZ_BUFSIZE
  73. #define UNZ_BUFSIZE (16384)
  74. #endif
  75. #ifndef UNZ_MAXFILENAMEINZIP
  76. #define UNZ_MAXFILENAMEINZIP (256)
  77. #endif
  78. #ifndef ALLOC
  79. # define ALLOC(size) (malloc(size))
  80. #endif
  81. #ifndef TRYFREE
  82. # define TRYFREE(p) { free(p);}
  83. #endif
  84. #define SIZECENTRALDIRITEM (0x2e)
  85. #define SIZEZIPLOCALHEADER (0x1e)
  86. const char unz_copyright[] =
  87. " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
  88. /* unz_file_info_interntal contain internal info about a file in zipfile*/
  89. typedef struct unz_file_info64_internal_s
  90. {
  91. ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */
  92. } unz_file_info64_internal;
  93. /* file_in_zip_read_info_s contain internal information about a file in zipfile,
  94. when reading and decompress it */
  95. typedef struct
  96. {
  97. char *read_buffer; /* internal buffer for compressed data */
  98. z_stream stream; /* zLib stream structure for inflate */
  99. #ifdef HAVE_BZIP2
  100. bz_stream bstream; /* bzLib stream structure for bziped */
  101. #endif
  102. ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
  103. uLong stream_initialised; /* flag set if stream structure is initialised*/
  104. ZPOS64_T offset_local_extrafield;/* offset of the local extra field */
  105. uInt size_local_extrafield;/* size of the local extra field */
  106. ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/
  107. ZPOS64_T total_out_64;
  108. uLong crc32; /* crc32 of all data uncompressed */
  109. uLong crc32_wait; /* crc32 we must obtain after decompress all */
  110. ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */
  111. ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/
  112. zlib_filefunc64_32_def z_filefunc;
  113. voidpf filestream; /* io structore of the zipfile */
  114. uLong compression_method; /* compression method (0==store) */
  115. ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
  116. int raw;
  117. /* GODOT start */
  118. int extra_size;
  119. /* GODOT end */
  120. } file_in_zip64_read_info_s;
  121. /* unz64_s contain internal information about the zipfile
  122. */
  123. typedef struct
  124. {
  125. zlib_filefunc64_32_def z_filefunc;
  126. int is64bitOpenFunction;
  127. voidpf filestream; /* io structore of the zipfile */
  128. unz_global_info64 gi; /* public global information */
  129. ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
  130. ZPOS64_T num_file; /* number of the current file in the zipfile*/
  131. ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/
  132. ZPOS64_T current_file_ok; /* flag about the usability of the current file*/
  133. ZPOS64_T central_pos; /* position of the beginning of the central dir*/
  134. ZPOS64_T size_central_dir; /* size of the central directory */
  135. ZPOS64_T offset_central_dir; /* offset of start of central directory with
  136. respect to the starting disk number */
  137. unz_file_info64 cur_file_info; /* public info about the current file in zip*/
  138. unz_file_info64_internal cur_file_info_internal; /* private info about it*/
  139. file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current
  140. file if we are decompressing it */
  141. int encrypted;
  142. int isZip64;
  143. # ifndef NOUNCRYPT
  144. unsigned long keys[3]; /* keys defining the pseudo-random sequence */
  145. const z_crc_t* pcrc_32_tab;
  146. # endif
  147. } unz64_s;
  148. #ifndef NOUNCRYPT
  149. #include "crypt.h"
  150. #endif
  151. /* ===========================================================================
  152. Read a byte from a gz_stream; update next_in and avail_in. Return EOF
  153. for end of file.
  154. IN assertion: the stream s has been successfully opened for reading.
  155. */
  156. local int unz64local_getByte OF((
  157. const zlib_filefunc64_32_def* pzlib_filefunc_def,
  158. voidpf filestream,
  159. int *pi));
  160. local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi)
  161. {
  162. unsigned char c;
  163. int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
  164. if (err==1)
  165. {
  166. *pi = (int)c;
  167. return UNZ_OK;
  168. }
  169. else
  170. {
  171. if (ZERROR64(*pzlib_filefunc_def,filestream))
  172. return UNZ_ERRNO;
  173. else
  174. return UNZ_EOF;
  175. }
  176. }
  177. /* ===========================================================================
  178. Reads a long in LSB order from the given gz_stream. Sets
  179. */
  180. local int unz64local_getShort OF((
  181. const zlib_filefunc64_32_def* pzlib_filefunc_def,
  182. voidpf filestream,
  183. uLong *pX));
  184. local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def,
  185. voidpf filestream,
  186. uLong *pX)
  187. {
  188. uLong x ;
  189. int i = 0;
  190. int err;
  191. err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  192. x = (uLong)i;
  193. if (err==UNZ_OK)
  194. err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  195. x |= ((uLong)i)<<8;
  196. if (err==UNZ_OK)
  197. *pX = x;
  198. else
  199. *pX = 0;
  200. return err;
  201. }
  202. local int unz64local_getLong OF((
  203. const zlib_filefunc64_32_def* pzlib_filefunc_def,
  204. voidpf filestream,
  205. uLong *pX));
  206. local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def,
  207. voidpf filestream,
  208. uLong *pX)
  209. {
  210. uLong x ;
  211. int i = 0;
  212. int err;
  213. err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  214. x = (uLong)i;
  215. if (err==UNZ_OK)
  216. err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  217. x |= ((uLong)i)<<8;
  218. if (err==UNZ_OK)
  219. err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  220. x |= ((uLong)i)<<16;
  221. if (err==UNZ_OK)
  222. err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  223. x += ((uLong)i)<<24;
  224. if (err==UNZ_OK)
  225. *pX = x;
  226. else
  227. *pX = 0;
  228. return err;
  229. }
  230. local int unz64local_getLong64 OF((
  231. const zlib_filefunc64_32_def* pzlib_filefunc_def,
  232. voidpf filestream,
  233. ZPOS64_T *pX));
  234. local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def,
  235. voidpf filestream,
  236. ZPOS64_T *pX)
  237. {
  238. ZPOS64_T x ;
  239. int i = 0;
  240. int err;
  241. err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  242. x = (ZPOS64_T)i;
  243. if (err==UNZ_OK)
  244. err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  245. x |= ((ZPOS64_T)i)<<8;
  246. if (err==UNZ_OK)
  247. err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  248. x |= ((ZPOS64_T)i)<<16;
  249. if (err==UNZ_OK)
  250. err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  251. x |= ((ZPOS64_T)i)<<24;
  252. if (err==UNZ_OK)
  253. err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  254. x |= ((ZPOS64_T)i)<<32;
  255. if (err==UNZ_OK)
  256. err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  257. x |= ((ZPOS64_T)i)<<40;
  258. if (err==UNZ_OK)
  259. err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  260. x |= ((ZPOS64_T)i)<<48;
  261. if (err==UNZ_OK)
  262. err = unz64local_getByte(pzlib_filefunc_def,filestream,&i);
  263. x |= ((ZPOS64_T)i)<<56;
  264. if (err==UNZ_OK)
  265. *pX = x;
  266. else
  267. *pX = 0;
  268. return err;
  269. }
  270. /* My own strcmpi / strcasecmp */
  271. local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2)
  272. {
  273. for (;;)
  274. {
  275. char c1=*(fileName1++);
  276. char c2=*(fileName2++);
  277. if ((c1>='a') && (c1<='z'))
  278. c1 -= 0x20;
  279. if ((c2>='a') && (c2<='z'))
  280. c2 -= 0x20;
  281. if (c1=='\0')
  282. return ((c2=='\0') ? 0 : -1);
  283. if (c2=='\0')
  284. return 1;
  285. if (c1<c2)
  286. return -1;
  287. if (c1>c2)
  288. return 1;
  289. }
  290. }
  291. #ifdef CASESENSITIVITYDEFAULT_NO
  292. #define CASESENSITIVITYDEFAULTVALUE 2
  293. #else
  294. #define CASESENSITIVITYDEFAULTVALUE 1
  295. #endif
  296. #ifndef STRCMPCASENOSENTIVEFUNCTION
  297. #define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal
  298. #endif
  299. /*
  300. Compare two filename (fileName1,fileName2).
  301. If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
  302. If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
  303. or strcasecmp)
  304. If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
  305. (like 1 on Unix, 2 on Windows)
  306. */
  307. extern int ZEXPORT unzStringFileNameCompare (const char* fileName1,
  308. const char* fileName2,
  309. int iCaseSensitivity)
  310. {
  311. if (iCaseSensitivity==0)
  312. iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE;
  313. if (iCaseSensitivity==1)
  314. return strcmp(fileName1,fileName2);
  315. return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2);
  316. }
  317. #ifndef BUFREADCOMMENT
  318. #define BUFREADCOMMENT (0x400)
  319. #endif
  320. /*
  321. Locate the Central directory of a zipfile (at the end, just before
  322. the global comment)
  323. */
  324. local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
  325. local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
  326. {
  327. unsigned char* buf;
  328. ZPOS64_T uSizeFile;
  329. ZPOS64_T uBackRead;
  330. ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
  331. ZPOS64_T uPosFound=0;
  332. if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
  333. return 0;
  334. uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
  335. if (uMaxBack>uSizeFile)
  336. uMaxBack = uSizeFile;
  337. buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
  338. if (buf==NULL)
  339. return 0;
  340. uBackRead = 4;
  341. while (uBackRead<uMaxBack)
  342. {
  343. uLong uReadSize;
  344. ZPOS64_T uReadPos ;
  345. int i;
  346. if (uBackRead+BUFREADCOMMENT>uMaxBack)
  347. uBackRead = uMaxBack;
  348. else
  349. uBackRead+=BUFREADCOMMENT;
  350. uReadPos = uSizeFile-uBackRead ;
  351. uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
  352. (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
  353. if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
  354. break;
  355. if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
  356. break;
  357. for (i=(int)uReadSize-3; (i--)>0;)
  358. if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
  359. ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
  360. {
  361. uPosFound = uReadPos+(unsigned)i;
  362. break;
  363. }
  364. if (uPosFound!=0)
  365. break;
  366. }
  367. TRYFREE(buf);
  368. return uPosFound;
  369. }
  370. /*
  371. Locate the Central directory 64 of a zipfile (at the end, just before
  372. the global comment)
  373. */
  374. local ZPOS64_T unz64local_SearchCentralDir64 OF((
  375. const zlib_filefunc64_32_def* pzlib_filefunc_def,
  376. voidpf filestream));
  377. local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def,
  378. voidpf filestream)
  379. {
  380. unsigned char* buf;
  381. ZPOS64_T uSizeFile;
  382. ZPOS64_T uBackRead;
  383. ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
  384. ZPOS64_T uPosFound=0;
  385. uLong uL;
  386. ZPOS64_T relativeOffset;
  387. if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
  388. return 0;
  389. uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
  390. if (uMaxBack>uSizeFile)
  391. uMaxBack = uSizeFile;
  392. buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
  393. if (buf==NULL)
  394. return 0;
  395. uBackRead = 4;
  396. while (uBackRead<uMaxBack)
  397. {
  398. uLong uReadSize;
  399. ZPOS64_T uReadPos;
  400. int i;
  401. if (uBackRead+BUFREADCOMMENT>uMaxBack)
  402. uBackRead = uMaxBack;
  403. else
  404. uBackRead+=BUFREADCOMMENT;
  405. uReadPos = uSizeFile-uBackRead ;
  406. uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
  407. (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
  408. if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
  409. break;
  410. if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
  411. break;
  412. for (i=(int)uReadSize-3; (i--)>0;)
  413. if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
  414. ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
  415. {
  416. uPosFound = uReadPos+(unsigned)i;
  417. break;
  418. }
  419. if (uPosFound!=0)
  420. break;
  421. }
  422. TRYFREE(buf);
  423. if (uPosFound == 0)
  424. return 0;
  425. /* Zip64 end of central directory locator */
  426. if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
  427. return 0;
  428. /* the signature, already checked */
  429. if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
  430. return 0;
  431. /* number of the disk with the start of the zip64 end of central directory */
  432. if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
  433. return 0;
  434. if (uL != 0)
  435. return 0;
  436. /* relative offset of the zip64 end of central directory record */
  437. if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK)
  438. return 0;
  439. /* total number of disks */
  440. if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
  441. return 0;
  442. if (uL != 1)
  443. return 0;
  444. /* Goto end of central directory record */
  445. if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
  446. return 0;
  447. /* the signature */
  448. if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK)
  449. return 0;
  450. if (uL != 0x06064b50)
  451. return 0;
  452. return relativeOffset;
  453. }
  454. /*
  455. Open a Zip file. path contain the full pathname (by example,
  456. on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer
  457. "zlib/zlib114.zip".
  458. If the zipfile cannot be opened (file doesn't exist or in not valid), the
  459. return value is NULL.
  460. Else, the return value is a unzFile Handle, usable with other function
  461. of this unzip package.
  462. */
  463. local unzFile unzOpenInternal (const void *path,
  464. zlib_filefunc64_32_def* pzlib_filefunc64_32_def,
  465. int is64bitOpenFunction)
  466. {
  467. unz64_s us;
  468. unz64_s *s;
  469. ZPOS64_T central_pos;
  470. uLong uL;
  471. uLong number_disk; /* number of the current dist, used for
  472. spaning ZIP, unsupported, always 0*/
  473. uLong number_disk_with_CD; /* number the the disk with central dir, used
  474. for spaning ZIP, unsupported, always 0*/
  475. ZPOS64_T number_entry_CD; /* total number of entries in
  476. the central dir
  477. (same than number_entry on nospan) */
  478. int err=UNZ_OK;
  479. if (unz_copyright[0]!=' ')
  480. return NULL;
  481. us.z_filefunc.zseek32_file = NULL;
  482. us.z_filefunc.ztell32_file = NULL;
  483. if (pzlib_filefunc64_32_def==NULL)
  484. /* GODOT start */
  485. return NULL; // standard i/o not supported
  486. us.z_filefunc = *pzlib_filefunc64_32_def;
  487. /* GODOT end */
  488. us.is64bitOpenFunction = is64bitOpenFunction;
  489. us.filestream = ZOPEN64(us.z_filefunc,
  490. path,
  491. ZLIB_FILEFUNC_MODE_READ |
  492. ZLIB_FILEFUNC_MODE_EXISTING);
  493. if (us.filestream==NULL)
  494. return NULL;
  495. central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream);
  496. if (central_pos)
  497. {
  498. uLong uS;
  499. ZPOS64_T uL64;
  500. us.isZip64 = 1;
  501. if (ZSEEK64(us.z_filefunc, us.filestream,
  502. central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
  503. err=UNZ_ERRNO;
  504. /* the signature, already checked */
  505. if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
  506. err=UNZ_ERRNO;
  507. /* size of zip64 end of central directory record */
  508. if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK)
  509. err=UNZ_ERRNO;
  510. /* version made by */
  511. if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
  512. err=UNZ_ERRNO;
  513. /* version needed to extract */
  514. if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK)
  515. err=UNZ_ERRNO;
  516. /* number of this disk */
  517. if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
  518. err=UNZ_ERRNO;
  519. /* number of the disk with the start of the central directory */
  520. if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
  521. err=UNZ_ERRNO;
  522. /* total number of entries in the central directory on this disk */
  523. if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK)
  524. err=UNZ_ERRNO;
  525. /* total number of entries in the central directory */
  526. if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK)
  527. err=UNZ_ERRNO;
  528. if ((number_entry_CD!=us.gi.number_entry) ||
  529. (number_disk_with_CD!=0) ||
  530. (number_disk!=0))
  531. err=UNZ_BADZIPFILE;
  532. /* size of the central directory */
  533. if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK)
  534. err=UNZ_ERRNO;
  535. /* offset of start of central directory with respect to the
  536. starting disk number */
  537. if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK)
  538. err=UNZ_ERRNO;
  539. us.gi.size_comment = 0;
  540. }
  541. else
  542. {
  543. central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream);
  544. if (central_pos==0)
  545. err=UNZ_ERRNO;
  546. us.isZip64 = 0;
  547. if (ZSEEK64(us.z_filefunc, us.filestream,
  548. central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
  549. err=UNZ_ERRNO;
  550. /* the signature, already checked */
  551. if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
  552. err=UNZ_ERRNO;
  553. /* number of this disk */
  554. if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK)
  555. err=UNZ_ERRNO;
  556. /* number of the disk with the start of the central directory */
  557. if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK)
  558. err=UNZ_ERRNO;
  559. /* total number of entries in the central dir on this disk */
  560. if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
  561. err=UNZ_ERRNO;
  562. us.gi.number_entry = uL;
  563. /* total number of entries in the central dir */
  564. if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
  565. err=UNZ_ERRNO;
  566. number_entry_CD = uL;
  567. if ((number_entry_CD!=us.gi.number_entry) ||
  568. (number_disk_with_CD!=0) ||
  569. (number_disk!=0))
  570. err=UNZ_BADZIPFILE;
  571. /* size of the central directory */
  572. if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
  573. err=UNZ_ERRNO;
  574. us.size_central_dir = uL;
  575. /* offset of start of central directory with respect to the
  576. starting disk number */
  577. if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK)
  578. err=UNZ_ERRNO;
  579. us.offset_central_dir = uL;
  580. /* zipfile comment length */
  581. if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK)
  582. err=UNZ_ERRNO;
  583. }
  584. if ((central_pos<us.offset_central_dir+us.size_central_dir) &&
  585. (err==UNZ_OK))
  586. err=UNZ_BADZIPFILE;
  587. if (err!=UNZ_OK)
  588. {
  589. ZCLOSE64(us.z_filefunc, us.filestream);
  590. return NULL;
  591. }
  592. us.byte_before_the_zipfile = central_pos -
  593. (us.offset_central_dir+us.size_central_dir);
  594. us.central_pos = central_pos;
  595. us.pfile_in_zip_read = NULL;
  596. us.encrypted = 0;
  597. s=(unz64_s*)ALLOC(sizeof(unz64_s));
  598. if( s != NULL)
  599. {
  600. *s=us;
  601. unzGoToFirstFile((unzFile)s);
  602. }
  603. return (unzFile)s;
  604. }
  605. extern unzFile ZEXPORT unzOpen2 (const char *path,
  606. zlib_filefunc_def* pzlib_filefunc32_def)
  607. {
  608. if (pzlib_filefunc32_def != NULL)
  609. {
  610. zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
  611. fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
  612. return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 0);
  613. }
  614. else
  615. return unzOpenInternal(path, NULL, 0);
  616. }
  617. extern unzFile ZEXPORT unzOpen2_64 (const void *path,
  618. zlib_filefunc64_def* pzlib_filefunc_def)
  619. {
  620. if (pzlib_filefunc_def != NULL)
  621. {
  622. zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
  623. zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
  624. zlib_filefunc64_32_def_fill.ztell32_file = NULL;
  625. zlib_filefunc64_32_def_fill.zseek32_file = NULL;
  626. return unzOpenInternal(path, &zlib_filefunc64_32_def_fill, 1);
  627. }
  628. else
  629. return unzOpenInternal(path, NULL, 1);
  630. }
  631. extern unzFile ZEXPORT unzOpen (const char *path)
  632. {
  633. return unzOpenInternal(path, NULL, 0);
  634. }
  635. extern unzFile ZEXPORT unzOpen64 (const void *path)
  636. {
  637. return unzOpenInternal(path, NULL, 1);
  638. }
  639. /* GODOT start */
  640. extern void* unzGetOpaque(unzFile file) {
  641. unz64_s* s;
  642. if (file==NULL)
  643. return NULL;
  644. s=(unz64_s*)file;
  645. return s->z_filefunc.zfile_func64.opaque;
  646. };
  647. /* GODOT end */
  648. /*
  649. Close a ZipFile opened with unzOpen.
  650. If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
  651. these files MUST be closed with unzCloseCurrentFile before call unzClose.
  652. return UNZ_OK if there is no problem. */
  653. extern int ZEXPORT unzClose (unzFile file)
  654. {
  655. unz64_s* s;
  656. if (file==NULL)
  657. return UNZ_PARAMERROR;
  658. s=(unz64_s*)file;
  659. if (s->pfile_in_zip_read!=NULL)
  660. unzCloseCurrentFile(file);
  661. ZCLOSE64(s->z_filefunc, s->filestream);
  662. TRYFREE(s);
  663. return UNZ_OK;
  664. }
  665. /*
  666. Write info about the ZipFile in the *pglobal_info structure.
  667. No preparation of the structure is needed
  668. return UNZ_OK if there is no problem. */
  669. extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info)
  670. {
  671. unz64_s* s;
  672. if (file==NULL)
  673. return UNZ_PARAMERROR;
  674. s=(unz64_s*)file;
  675. *pglobal_info=s->gi;
  676. return UNZ_OK;
  677. }
  678. extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32)
  679. {
  680. unz64_s* s;
  681. if (file==NULL)
  682. return UNZ_PARAMERROR;
  683. s=(unz64_s*)file;
  684. /* to do : check if number_entry is not truncated */
  685. pglobal_info32->number_entry = (uLong)s->gi.number_entry;
  686. pglobal_info32->size_comment = s->gi.size_comment;
  687. return UNZ_OK;
  688. }
  689. /*
  690. Translate date/time from Dos format to tm_unz (readable more easilty)
  691. */
  692. local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm)
  693. {
  694. ZPOS64_T uDate;
  695. uDate = (ZPOS64_T)(ulDosDate>>16);
  696. ptm->tm_mday = (int)(uDate&0x1f) ;
  697. ptm->tm_mon = (int)((((uDate)&0x1E0)/0x20)-1) ;
  698. ptm->tm_year = (int)(((uDate&0x0FE00)/0x0200)+1980) ;
  699. ptm->tm_hour = (int) ((ulDosDate &0xF800)/0x800);
  700. ptm->tm_min = (int) ((ulDosDate&0x7E0)/0x20) ;
  701. ptm->tm_sec = (int) (2*(ulDosDate&0x1f)) ;
  702. }
  703. /*
  704. Get Info about the current file in the zipfile, with internal only info
  705. */
  706. local int unz64local_GetCurrentFileInfoInternal OF((unzFile file,
  707. unz_file_info64 *pfile_info,
  708. unz_file_info64_internal
  709. *pfile_info_internal,
  710. char *szFileName,
  711. uLong fileNameBufferSize,
  712. void *extraField,
  713. uLong extraFieldBufferSize,
  714. char *szComment,
  715. uLong commentBufferSize));
  716. local int unz64local_GetCurrentFileInfoInternal (unzFile file,
  717. unz_file_info64 *pfile_info,
  718. unz_file_info64_internal
  719. *pfile_info_internal,
  720. char *szFileName,
  721. uLong fileNameBufferSize,
  722. void *extraField,
  723. uLong extraFieldBufferSize,
  724. char *szComment,
  725. uLong commentBufferSize)
  726. {
  727. unz64_s* s;
  728. unz_file_info64 file_info;
  729. unz_file_info64_internal file_info_internal;
  730. int err=UNZ_OK;
  731. uLong uMagic;
  732. long lSeek=0;
  733. uLong uL;
  734. if (file==NULL)
  735. return UNZ_PARAMERROR;
  736. s=(unz64_s*)file;
  737. if (ZSEEK64(s->z_filefunc, s->filestream,
  738. s->pos_in_central_dir+s->byte_before_the_zipfile,
  739. ZLIB_FILEFUNC_SEEK_SET)!=0)
  740. err=UNZ_ERRNO;
  741. /* we check the magic */
  742. if (err==UNZ_OK)
  743. {
  744. if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
  745. err=UNZ_ERRNO;
  746. else if (uMagic!=0x02014b50)
  747. err=UNZ_BADZIPFILE;
  748. }
  749. if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK)
  750. err=UNZ_ERRNO;
  751. if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK)
  752. err=UNZ_ERRNO;
  753. if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK)
  754. err=UNZ_ERRNO;
  755. if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK)
  756. err=UNZ_ERRNO;
  757. if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK)
  758. err=UNZ_ERRNO;
  759. unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date);
  760. if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK)
  761. err=UNZ_ERRNO;
  762. if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
  763. err=UNZ_ERRNO;
  764. file_info.compressed_size = uL;
  765. if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
  766. err=UNZ_ERRNO;
  767. file_info.uncompressed_size = uL;
  768. if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK)
  769. err=UNZ_ERRNO;
  770. if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK)
  771. err=UNZ_ERRNO;
  772. if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK)
  773. err=UNZ_ERRNO;
  774. if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK)
  775. err=UNZ_ERRNO;
  776. if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK)
  777. err=UNZ_ERRNO;
  778. if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK)
  779. err=UNZ_ERRNO;
  780. // relative offset of local header
  781. if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
  782. err=UNZ_ERRNO;
  783. file_info_internal.offset_curfile = uL;
  784. lSeek+=file_info.size_filename;
  785. if ((err==UNZ_OK) && (szFileName!=NULL))
  786. {
  787. uLong uSizeRead ;
  788. if (file_info.size_filename<fileNameBufferSize)
  789. {
  790. *(szFileName+file_info.size_filename)='\0';
  791. uSizeRead = file_info.size_filename;
  792. }
  793. else
  794. uSizeRead = fileNameBufferSize;
  795. if ((file_info.size_filename>0) && (fileNameBufferSize>0))
  796. if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead)
  797. err=UNZ_ERRNO;
  798. lSeek -= uSizeRead;
  799. }
  800. // Read extrafield
  801. if ((err==UNZ_OK) && (extraField!=NULL))
  802. {
  803. ZPOS64_T uSizeRead ;
  804. if (file_info.size_file_extra<extraFieldBufferSize)
  805. uSizeRead = file_info.size_file_extra;
  806. else
  807. uSizeRead = extraFieldBufferSize;
  808. if (lSeek!=0)
  809. {
  810. if (ZSEEK64(s->z_filefunc, s->filestream,(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
  811. lSeek=0;
  812. else
  813. err=UNZ_ERRNO;
  814. }
  815. if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
  816. if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead)
  817. err=UNZ_ERRNO;
  818. lSeek += file_info.size_file_extra - (uLong)uSizeRead;
  819. }
  820. else
  821. lSeek += file_info.size_file_extra;
  822. if ((err==UNZ_OK) && (file_info.size_file_extra != 0))
  823. {
  824. uLong acc = 0;
  825. // since lSeek now points to after the extra field we need to move back
  826. lSeek -= file_info.size_file_extra;
  827. if (lSeek!=0)
  828. {
  829. /* GODOT start */
  830. if (lSeek<0) {
  831. // WORKAROUND for backwards seeking
  832. ZPOS64_T pos = ZTELL64(s->z_filefunc, s->filestream);
  833. if (ZSEEK64(s->z_filefunc, s->filestream,pos+(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_SET)==0)
  834. lSeek=0;
  835. else
  836. err=UNZ_ERRNO;
  837. } else {
  838. /* GODOT end */
  839. if (ZSEEK64(s->z_filefunc, s->filestream,(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
  840. lSeek=0;
  841. else
  842. err=UNZ_ERRNO;
  843. /* GODOT start */
  844. }
  845. /* GODOT end */
  846. }
  847. while(acc < file_info.size_file_extra)
  848. {
  849. uLong headerId;
  850. uLong dataSize;
  851. if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK)
  852. err=UNZ_ERRNO;
  853. if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK)
  854. err=UNZ_ERRNO;
  855. /* ZIP64 extra fields */
  856. if (headerId == 0x0001)
  857. {
  858. uLong uL;
  859. if(file_info.uncompressed_size == MAXU32)
  860. {
  861. if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK)
  862. err=UNZ_ERRNO;
  863. }
  864. if(file_info.compressed_size == MAXU32)
  865. {
  866. if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK)
  867. err=UNZ_ERRNO;
  868. }
  869. if(file_info_internal.offset_curfile == MAXU32)
  870. {
  871. /* Relative Header offset */
  872. if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK)
  873. err=UNZ_ERRNO;
  874. }
  875. if(file_info.disk_num_start == MAXU32)
  876. {
  877. /* Disk Start Number */
  878. if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK)
  879. err=UNZ_ERRNO;
  880. }
  881. }
  882. else
  883. {
  884. if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0)
  885. err=UNZ_ERRNO;
  886. }
  887. acc += 2 + 2 + dataSize;
  888. }
  889. }
  890. if ((err==UNZ_OK) && (szComment!=NULL))
  891. {
  892. uLong uSizeRead ;
  893. if (file_info.size_file_comment<commentBufferSize)
  894. {
  895. *(szComment+file_info.size_file_comment)='\0';
  896. uSizeRead = file_info.size_file_comment;
  897. }
  898. else
  899. uSizeRead = commentBufferSize;
  900. if (lSeek!=0)
  901. {
  902. if (ZSEEK64(s->z_filefunc, s->filestream,(ZPOS64_T)lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
  903. lSeek=0;
  904. else
  905. err=UNZ_ERRNO;
  906. }
  907. if ((file_info.size_file_comment>0) && (commentBufferSize>0))
  908. if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead)
  909. err=UNZ_ERRNO;
  910. lSeek+=file_info.size_file_comment - uSizeRead;
  911. }
  912. else
  913. lSeek+=file_info.size_file_comment;
  914. if ((err==UNZ_OK) && (pfile_info!=NULL))
  915. *pfile_info=file_info;
  916. if ((err==UNZ_OK) && (pfile_info_internal!=NULL))
  917. *pfile_info_internal=file_info_internal;
  918. return err;
  919. }
  920. /*
  921. Write info about the ZipFile in the *pglobal_info structure.
  922. No preparation of the structure is needed
  923. return UNZ_OK if there is no problem.
  924. */
  925. extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file,
  926. unz_file_info64 * pfile_info,
  927. char * szFileName, uLong fileNameBufferSize,
  928. void *extraField, uLong extraFieldBufferSize,
  929. char* szComment, uLong commentBufferSize)
  930. {
  931. return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL,
  932. szFileName,fileNameBufferSize,
  933. extraField,extraFieldBufferSize,
  934. szComment,commentBufferSize);
  935. }
  936. extern int ZEXPORT unzGetCurrentFileInfo (unzFile file,
  937. unz_file_info * pfile_info,
  938. char * szFileName, uLong fileNameBufferSize,
  939. void *extraField, uLong extraFieldBufferSize,
  940. char* szComment, uLong commentBufferSize)
  941. {
  942. int err;
  943. unz_file_info64 file_info64;
  944. err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL,
  945. szFileName,fileNameBufferSize,
  946. extraField,extraFieldBufferSize,
  947. szComment,commentBufferSize);
  948. if ((err==UNZ_OK) && (pfile_info != NULL))
  949. {
  950. pfile_info->version = file_info64.version;
  951. pfile_info->version_needed = file_info64.version_needed;
  952. pfile_info->flag = file_info64.flag;
  953. pfile_info->compression_method = file_info64.compression_method;
  954. pfile_info->dosDate = file_info64.dosDate;
  955. pfile_info->crc = file_info64.crc;
  956. pfile_info->size_filename = file_info64.size_filename;
  957. pfile_info->size_file_extra = file_info64.size_file_extra;
  958. pfile_info->size_file_comment = file_info64.size_file_comment;
  959. pfile_info->disk_num_start = file_info64.disk_num_start;
  960. pfile_info->internal_fa = file_info64.internal_fa;
  961. pfile_info->external_fa = file_info64.external_fa;
  962. pfile_info->tmu_date = file_info64.tmu_date,
  963. pfile_info->compressed_size = (uLong)file_info64.compressed_size;
  964. pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size;
  965. }
  966. return err;
  967. }
  968. /*
  969. Set the current file of the zipfile to the first file.
  970. return UNZ_OK if there is no problem
  971. */
  972. extern int ZEXPORT unzGoToFirstFile (unzFile file)
  973. {
  974. int err=UNZ_OK;
  975. unz64_s* s;
  976. if (file==NULL)
  977. return UNZ_PARAMERROR;
  978. s=(unz64_s*)file;
  979. s->pos_in_central_dir=s->offset_central_dir;
  980. s->num_file=0;
  981. err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
  982. &s->cur_file_info_internal,
  983. NULL,0,NULL,0,NULL,0);
  984. s->current_file_ok = (err == UNZ_OK);
  985. return err;
  986. }
  987. /*
  988. Set the current file of the zipfile to the next file.
  989. return UNZ_OK if there is no problem
  990. return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
  991. */
  992. extern int ZEXPORT unzGoToNextFile (unzFile file)
  993. {
  994. unz64_s* s;
  995. int err;
  996. if (file==NULL)
  997. return UNZ_PARAMERROR;
  998. s=(unz64_s*)file;
  999. if (!s->current_file_ok)
  1000. return UNZ_END_OF_LIST_OF_FILE;
  1001. if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */
  1002. if (s->num_file+1==s->gi.number_entry)
  1003. return UNZ_END_OF_LIST_OF_FILE;
  1004. s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename +
  1005. s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ;
  1006. s->num_file++;
  1007. err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
  1008. &s->cur_file_info_internal,
  1009. NULL,0,NULL,0,NULL,0);
  1010. s->current_file_ok = (err == UNZ_OK);
  1011. return err;
  1012. }
  1013. /*
  1014. Try locate the file szFileName in the zipfile.
  1015. For the iCaseSensitivity signification, see unzStringFileNameCompare
  1016. return value :
  1017. UNZ_OK if the file is found. It becomes the current file.
  1018. UNZ_END_OF_LIST_OF_FILE if the file is not found
  1019. */
  1020. extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity)
  1021. {
  1022. unz64_s* s;
  1023. int err;
  1024. /* We remember the 'current' position in the file so that we can jump
  1025. * back there if we fail.
  1026. */
  1027. unz_file_info64 cur_file_infoSaved;
  1028. unz_file_info64_internal cur_file_info_internalSaved;
  1029. ZPOS64_T num_fileSaved;
  1030. ZPOS64_T pos_in_central_dirSaved;
  1031. if (file==NULL)
  1032. return UNZ_PARAMERROR;
  1033. if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP)
  1034. return UNZ_PARAMERROR;
  1035. s=(unz64_s*)file;
  1036. if (!s->current_file_ok)
  1037. return UNZ_END_OF_LIST_OF_FILE;
  1038. /* Save the current state */
  1039. num_fileSaved = s->num_file;
  1040. pos_in_central_dirSaved = s->pos_in_central_dir;
  1041. cur_file_infoSaved = s->cur_file_info;
  1042. cur_file_info_internalSaved = s->cur_file_info_internal;
  1043. err = unzGoToFirstFile(file);
  1044. while (err == UNZ_OK)
  1045. {
  1046. char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
  1047. err = unzGetCurrentFileInfo64(file,NULL,
  1048. szCurrentFileName,sizeof(szCurrentFileName)-1,
  1049. NULL,0,NULL,0);
  1050. if (err == UNZ_OK)
  1051. {
  1052. if (unzStringFileNameCompare(szCurrentFileName,
  1053. szFileName,iCaseSensitivity)==0)
  1054. return UNZ_OK;
  1055. err = unzGoToNextFile(file);
  1056. }
  1057. }
  1058. /* We failed, so restore the state of the 'current file' to where we
  1059. * were.
  1060. */
  1061. s->num_file = num_fileSaved ;
  1062. s->pos_in_central_dir = pos_in_central_dirSaved ;
  1063. s->cur_file_info = cur_file_infoSaved;
  1064. s->cur_file_info_internal = cur_file_info_internalSaved;
  1065. return err;
  1066. }
  1067. /*
  1068. ///////////////////////////////////////////
  1069. // Contributed by Ryan Haksi (mailto://cryogen@infoserve.net)
  1070. // I need random access
  1071. //
  1072. // Further optimization could be realized by adding an ability
  1073. // to cache the directory in memory. The goal being a single
  1074. // comprehensive file read to put the file I need in a memory.
  1075. */
  1076. /*
  1077. typedef struct unz_file_pos_s
  1078. {
  1079. ZPOS64_T pos_in_zip_directory; // offset in file
  1080. ZPOS64_T num_of_file; // # of file
  1081. } unz_file_pos;
  1082. */
  1083. extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos)
  1084. {
  1085. unz64_s* s;
  1086. if (file==NULL || file_pos==NULL)
  1087. return UNZ_PARAMERROR;
  1088. s=(unz64_s*)file;
  1089. if (!s->current_file_ok)
  1090. return UNZ_END_OF_LIST_OF_FILE;
  1091. file_pos->pos_in_zip_directory = s->pos_in_central_dir;
  1092. file_pos->num_of_file = s->num_file;
  1093. return UNZ_OK;
  1094. }
  1095. extern int ZEXPORT unzGetFilePos(
  1096. unzFile file,
  1097. unz_file_pos* file_pos)
  1098. {
  1099. unz64_file_pos file_pos64;
  1100. int err = unzGetFilePos64(file,&file_pos64);
  1101. if (err==UNZ_OK)
  1102. {
  1103. file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory;
  1104. file_pos->num_of_file = (uLong)file_pos64.num_of_file;
  1105. }
  1106. return err;
  1107. }
  1108. extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos)
  1109. {
  1110. unz64_s* s;
  1111. int err;
  1112. if (file==NULL || file_pos==NULL)
  1113. return UNZ_PARAMERROR;
  1114. s=(unz64_s*)file;
  1115. /* jump to the right spot */
  1116. s->pos_in_central_dir = file_pos->pos_in_zip_directory;
  1117. s->num_file = file_pos->num_of_file;
  1118. /* set the current file */
  1119. err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
  1120. &s->cur_file_info_internal,
  1121. NULL,0,NULL,0,NULL,0);
  1122. /* return results */
  1123. s->current_file_ok = (err == UNZ_OK);
  1124. return err;
  1125. }
  1126. extern int ZEXPORT unzGoToFilePos(
  1127. unzFile file,
  1128. unz_file_pos* file_pos)
  1129. {
  1130. unz64_file_pos file_pos64;
  1131. if (file_pos == NULL)
  1132. return UNZ_PARAMERROR;
  1133. file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory;
  1134. file_pos64.num_of_file = file_pos->num_of_file;
  1135. return unzGoToFilePos64(file,&file_pos64);
  1136. }
  1137. /*
  1138. // Unzip Helper Functions - should be here?
  1139. ///////////////////////////////////////////
  1140. */
  1141. /*
  1142. Read the local header of the current zipfile
  1143. Check the coherency of the local header and info in the end of central
  1144. directory about this file
  1145. store in *piSizeVar the size of extra info in local header
  1146. (filename and size of extra field data)
  1147. */
  1148. local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar,
  1149. ZPOS64_T * poffset_local_extrafield,
  1150. uInt * psize_local_extrafield)
  1151. {
  1152. uLong uMagic,uData,uFlags;
  1153. uLong size_filename;
  1154. uLong size_extra_field;
  1155. int err=UNZ_OK;
  1156. *piSizeVar = 0;
  1157. *poffset_local_extrafield = 0;
  1158. *psize_local_extrafield = 0;
  1159. if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile +
  1160. s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0)
  1161. return UNZ_ERRNO;
  1162. if (err==UNZ_OK)
  1163. {
  1164. if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK)
  1165. err=UNZ_ERRNO;
  1166. else if (uMagic!=0x04034b50)
  1167. err=UNZ_BADZIPFILE;
  1168. }
  1169. if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
  1170. err=UNZ_ERRNO;
  1171. /*
  1172. else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion))
  1173. err=UNZ_BADZIPFILE;
  1174. */
  1175. if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK)
  1176. err=UNZ_ERRNO;
  1177. if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
  1178. err=UNZ_ERRNO;
  1179. else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method))
  1180. err=UNZ_BADZIPFILE;
  1181. if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) &&
  1182. /* #ifdef HAVE_BZIP2 */
  1183. (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
  1184. /* #endif */
  1185. (s->cur_file_info.compression_method!=Z_DEFLATED))
  1186. err=UNZ_BADZIPFILE;
  1187. if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */
  1188. err=UNZ_ERRNO;
  1189. if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */
  1190. err=UNZ_ERRNO;
  1191. else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0))
  1192. err=UNZ_BADZIPFILE;
  1193. if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */
  1194. err=UNZ_ERRNO;
  1195. else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0))
  1196. err=UNZ_BADZIPFILE;
  1197. if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */
  1198. err=UNZ_ERRNO;
  1199. else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0))
  1200. err=UNZ_BADZIPFILE;
  1201. if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK)
  1202. err=UNZ_ERRNO;
  1203. else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename))
  1204. err=UNZ_BADZIPFILE;
  1205. *piSizeVar += (uInt)size_filename;
  1206. if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK)
  1207. err=UNZ_ERRNO;
  1208. *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile +
  1209. SIZEZIPLOCALHEADER + size_filename;
  1210. *psize_local_extrafield = (uInt)size_extra_field;
  1211. *piSizeVar += (uInt)size_extra_field;
  1212. return err;
  1213. }
  1214. /*
  1215. Open for reading data the current file in the zipfile.
  1216. If there is no error and the file is opened, the return value is UNZ_OK.
  1217. */
  1218. extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method,
  1219. int* level, int raw, const char* password)
  1220. {
  1221. int err=UNZ_OK;
  1222. uInt iSizeVar;
  1223. unz64_s* s;
  1224. file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1225. ZPOS64_T offset_local_extrafield; /* offset of the local extra field */
  1226. uInt size_local_extrafield; /* size of the local extra field */
  1227. # ifndef NOUNCRYPT
  1228. char source[12];
  1229. # else
  1230. if (password != NULL)
  1231. return UNZ_PARAMERROR;
  1232. # endif
  1233. if (file==NULL)
  1234. return UNZ_PARAMERROR;
  1235. s=(unz64_s*)file;
  1236. if (!s->current_file_ok)
  1237. return UNZ_PARAMERROR;
  1238. if (s->pfile_in_zip_read != NULL)
  1239. unzCloseCurrentFile(file);
  1240. if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK)
  1241. return UNZ_BADZIPFILE;
  1242. pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s));
  1243. if (pfile_in_zip_read_info==NULL)
  1244. return UNZ_INTERNALERROR;
  1245. pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE);
  1246. pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield;
  1247. pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield;
  1248. pfile_in_zip_read_info->pos_local_extrafield=0;
  1249. pfile_in_zip_read_info->raw=raw;
  1250. if (pfile_in_zip_read_info->read_buffer==NULL)
  1251. {
  1252. TRYFREE(pfile_in_zip_read_info);
  1253. return UNZ_INTERNALERROR;
  1254. }
  1255. pfile_in_zip_read_info->stream_initialised=0;
  1256. if (method!=NULL)
  1257. *method = (int)s->cur_file_info.compression_method;
  1258. if (level!=NULL)
  1259. {
  1260. *level = 6;
  1261. switch (s->cur_file_info.flag & 0x06)
  1262. {
  1263. case 6 : *level = 1; break;
  1264. case 4 : *level = 2; break;
  1265. case 2 : *level = 9; break;
  1266. }
  1267. }
  1268. if ((s->cur_file_info.compression_method!=0) &&
  1269. /* #ifdef HAVE_BZIP2 */
  1270. (s->cur_file_info.compression_method!=Z_BZIP2ED) &&
  1271. /* #endif */
  1272. (s->cur_file_info.compression_method!=Z_DEFLATED))
  1273. err=UNZ_BADZIPFILE;
  1274. pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc;
  1275. pfile_in_zip_read_info->crc32=0;
  1276. pfile_in_zip_read_info->total_out_64=0;
  1277. pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method;
  1278. pfile_in_zip_read_info->filestream=s->filestream;
  1279. pfile_in_zip_read_info->z_filefunc=s->z_filefunc;
  1280. pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile;
  1281. pfile_in_zip_read_info->stream.total_out = 0;
  1282. if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw))
  1283. {
  1284. #ifdef HAVE_BZIP2
  1285. pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0;
  1286. pfile_in_zip_read_info->bstream.bzfree = (free_func)0;
  1287. pfile_in_zip_read_info->bstream.opaque = (voidpf)0;
  1288. pfile_in_zip_read_info->bstream.state = (voidpf)0;
  1289. pfile_in_zip_read_info->stream.zalloc = (alloc_func)0;
  1290. pfile_in_zip_read_info->stream.zfree = (free_func)0;
  1291. pfile_in_zip_read_info->stream.opaque = (voidpf)0;
  1292. pfile_in_zip_read_info->stream.next_in = (voidpf)0;
  1293. pfile_in_zip_read_info->stream.avail_in = 0;
  1294. err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0);
  1295. if (err == Z_OK)
  1296. pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED;
  1297. else
  1298. {
  1299. TRYFREE(pfile_in_zip_read_info->read_buffer);
  1300. TRYFREE(pfile_in_zip_read_info);
  1301. return err;
  1302. }
  1303. #else
  1304. pfile_in_zip_read_info->raw=1;
  1305. #endif
  1306. }
  1307. else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw))
  1308. {
  1309. /* GODOT start */
  1310. pfile_in_zip_read_info->stream.zalloc = s->z_filefunc.zfile_func64.alloc_mem;
  1311. pfile_in_zip_read_info->stream.zfree = s->z_filefunc.zfile_func64.free_mem;
  1312. /* GODOT end */
  1313. pfile_in_zip_read_info->stream.opaque = (voidpf)0;
  1314. pfile_in_zip_read_info->stream.next_in = 0;
  1315. pfile_in_zip_read_info->stream.avail_in = 0;
  1316. err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS);
  1317. if (err == Z_OK)
  1318. pfile_in_zip_read_info->stream_initialised=Z_DEFLATED;
  1319. else
  1320. {
  1321. TRYFREE(pfile_in_zip_read_info->read_buffer);
  1322. TRYFREE(pfile_in_zip_read_info);
  1323. return err;
  1324. }
  1325. /* windowBits is passed < 0 to tell that there is no zlib header.
  1326. * Note that in this case inflate *requires* an extra "dummy" byte
  1327. * after the compressed stream in order to complete decompression and
  1328. * return Z_STREAM_END.
  1329. * In unzip, i don't wait absolutely Z_STREAM_END because I known the
  1330. * size of both compressed and uncompressed data
  1331. */
  1332. }
  1333. pfile_in_zip_read_info->rest_read_compressed =
  1334. s->cur_file_info.compressed_size ;
  1335. pfile_in_zip_read_info->rest_read_uncompressed =
  1336. s->cur_file_info.uncompressed_size ;
  1337. pfile_in_zip_read_info->pos_in_zipfile =
  1338. s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
  1339. iSizeVar;
  1340. pfile_in_zip_read_info->stream.avail_in = (uInt)0;
  1341. /* GODOT start */
  1342. pfile_in_zip_read_info->extra_size = iSizeVar;
  1343. /* GODOT end */
  1344. s->pfile_in_zip_read = pfile_in_zip_read_info;
  1345. s->encrypted = 0;
  1346. # ifndef NOUNCRYPT
  1347. if (password != NULL)
  1348. {
  1349. int i;
  1350. s->pcrc_32_tab = get_crc_table();
  1351. init_keys(password,s->keys,s->pcrc_32_tab);
  1352. if (ZSEEK64(s->z_filefunc, s->filestream,
  1353. s->pfile_in_zip_read->pos_in_zipfile +
  1354. s->pfile_in_zip_read->byte_before_the_zipfile,
  1355. SEEK_SET)!=0)
  1356. return UNZ_INTERNALERROR;
  1357. if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12)
  1358. return UNZ_INTERNALERROR;
  1359. for (i = 0; i<12; i++)
  1360. zdecode(s->keys,s->pcrc_32_tab,source[i]);
  1361. s->pfile_in_zip_read->pos_in_zipfile+=12;
  1362. s->encrypted=1;
  1363. }
  1364. # endif
  1365. return UNZ_OK;
  1366. }
  1367. /* GODOT start */
  1368. extern int ZEXPORT unzSeekCurrentFile(unzFile file, int pos) {
  1369. unz64_s* s;
  1370. file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1371. if (file==NULL)
  1372. return UNZ_PARAMERROR;
  1373. s=(unz64_s*)file;
  1374. pfile_in_zip_read_info=s->pfile_in_zip_read;
  1375. if (pfile_in_zip_read_info==NULL)
  1376. return UNZ_PARAMERROR;
  1377. if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED) { // don't know how to support bzip
  1378. return UNZ_INTERNALERROR;
  1379. }
  1380. if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) {
  1381. pfile_in_zip_read_info->rest_read_compressed =
  1382. s->cur_file_info.compressed_size - pos;
  1383. pfile_in_zip_read_info->rest_read_uncompressed =
  1384. s->cur_file_info.uncompressed_size - pos;
  1385. pfile_in_zip_read_info->pos_in_zipfile =
  1386. s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
  1387. pfile_in_zip_read_info->extra_size + pos;
  1388. pfile_in_zip_read_info->stream.avail_in = (uInt)0;
  1389. pfile_in_zip_read_info->stream.total_out = pos;
  1390. return ZSEEK64(pfile_in_zip_read_info->z_filefunc,
  1391. pfile_in_zip_read_info->filestream,
  1392. pfile_in_zip_read_info->byte_before_the_zipfile + pfile_in_zip_read_info->pos_in_zipfile,
  1393. ZLIB_FILEFUNC_SEEK_SET);
  1394. } else { // gzip
  1395. if (pos < pfile_in_zip_read_info->stream.total_out) { // negative seek, rewind
  1396. pfile_in_zip_read_info->rest_read_compressed =
  1397. s->cur_file_info.compressed_size ;
  1398. pfile_in_zip_read_info->rest_read_uncompressed =
  1399. s->cur_file_info.uncompressed_size ;
  1400. pfile_in_zip_read_info->pos_in_zipfile =
  1401. s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER +
  1402. pfile_in_zip_read_info->extra_size;
  1403. (void)inflateReset(&pfile_in_zip_read_info->stream);
  1404. pfile_in_zip_read_info->stream.avail_in = (uInt)0;
  1405. pfile_in_zip_read_info->stream.total_out = 0;
  1406. pfile_in_zip_read_info->stream.next_in = 0;
  1407. }
  1408. // not sure where to read, so read on the stack
  1409. {
  1410. char buf[512];
  1411. int to_read = pos - pfile_in_zip_read_info->stream.total_out;
  1412. while (to_read) {
  1413. int len = to_read > sizeof(buf)?sizeof(buf):to_read;
  1414. int read = unzReadCurrentFile(file, buf, len);
  1415. if (read < 0) {
  1416. return read;
  1417. }
  1418. to_read -= read;
  1419. if (read == UNZ_EOF) {
  1420. return pos;
  1421. }
  1422. }
  1423. }
  1424. }
  1425. return pos;
  1426. }
  1427. /* GODOT end */
  1428. extern int ZEXPORT unzOpenCurrentFile (unzFile file)
  1429. {
  1430. return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL);
  1431. }
  1432. extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password)
  1433. {
  1434. return unzOpenCurrentFile3(file, NULL, NULL, 0, password);
  1435. }
  1436. extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw)
  1437. {
  1438. return unzOpenCurrentFile3(file, method, level, raw, NULL);
  1439. }
  1440. /** Addition for GDAL : START */
  1441. extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file)
  1442. {
  1443. unz64_s* s;
  1444. file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1445. s=(unz64_s*)file;
  1446. if (file==NULL)
  1447. return 0; //UNZ_PARAMERROR;
  1448. pfile_in_zip_read_info=s->pfile_in_zip_read;
  1449. if (pfile_in_zip_read_info==NULL)
  1450. return 0; //UNZ_PARAMERROR;
  1451. return pfile_in_zip_read_info->pos_in_zipfile +
  1452. pfile_in_zip_read_info->byte_before_the_zipfile;
  1453. }
  1454. /** Addition for GDAL : END */
  1455. /*
  1456. Read bytes from the current file.
  1457. buf contain buffer where data must be copied
  1458. len the size of buf.
  1459. return the number of byte copied if somes bytes are copied
  1460. return 0 if the end of file was reached
  1461. return <0 with error code if there is an error
  1462. (UNZ_ERRNO for IO error, or zLib error for uncompress error)
  1463. */
  1464. extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len)
  1465. {
  1466. int err=UNZ_OK;
  1467. uInt iRead = 0;
  1468. unz64_s* s;
  1469. file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1470. if (file==NULL)
  1471. return UNZ_PARAMERROR;
  1472. s=(unz64_s*)file;
  1473. pfile_in_zip_read_info=s->pfile_in_zip_read;
  1474. if (pfile_in_zip_read_info==NULL)
  1475. return UNZ_PARAMERROR;
  1476. if (pfile_in_zip_read_info->read_buffer == NULL)
  1477. return UNZ_END_OF_LIST_OF_FILE;
  1478. if (len==0)
  1479. return 0;
  1480. pfile_in_zip_read_info->stream.next_out = (Bytef*)buf;
  1481. pfile_in_zip_read_info->stream.avail_out = (uInt)len;
  1482. if ((len>pfile_in_zip_read_info->rest_read_uncompressed) &&
  1483. (!(pfile_in_zip_read_info->raw)))
  1484. pfile_in_zip_read_info->stream.avail_out =
  1485. (uInt)pfile_in_zip_read_info->rest_read_uncompressed;
  1486. if ((len>pfile_in_zip_read_info->rest_read_compressed+
  1487. pfile_in_zip_read_info->stream.avail_in) &&
  1488. (pfile_in_zip_read_info->raw))
  1489. pfile_in_zip_read_info->stream.avail_out =
  1490. (uInt)pfile_in_zip_read_info->rest_read_compressed+
  1491. pfile_in_zip_read_info->stream.avail_in;
  1492. while (pfile_in_zip_read_info->stream.avail_out>0)
  1493. {
  1494. if ((pfile_in_zip_read_info->stream.avail_in==0) &&
  1495. (pfile_in_zip_read_info->rest_read_compressed>0))
  1496. {
  1497. uInt uReadThis = UNZ_BUFSIZE;
  1498. if (pfile_in_zip_read_info->rest_read_compressed<uReadThis)
  1499. uReadThis = (uInt)pfile_in_zip_read_info->rest_read_compressed;
  1500. if (uReadThis == 0)
  1501. return UNZ_EOF;
  1502. if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
  1503. pfile_in_zip_read_info->filestream,
  1504. pfile_in_zip_read_info->pos_in_zipfile +
  1505. pfile_in_zip_read_info->byte_before_the_zipfile,
  1506. ZLIB_FILEFUNC_SEEK_SET)!=0)
  1507. return UNZ_ERRNO;
  1508. if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
  1509. pfile_in_zip_read_info->filestream,
  1510. pfile_in_zip_read_info->read_buffer,
  1511. uReadThis)!=uReadThis)
  1512. return UNZ_ERRNO;
  1513. # ifndef NOUNCRYPT
  1514. if(s->encrypted)
  1515. {
  1516. uInt i;
  1517. for(i=0;i<uReadThis;i++)
  1518. pfile_in_zip_read_info->read_buffer[i] =
  1519. zdecode(s->keys,s->pcrc_32_tab,
  1520. pfile_in_zip_read_info->read_buffer[i]);
  1521. }
  1522. # endif
  1523. pfile_in_zip_read_info->pos_in_zipfile += uReadThis;
  1524. pfile_in_zip_read_info->rest_read_compressed-=uReadThis;
  1525. pfile_in_zip_read_info->stream.next_in =
  1526. (Bytef*)pfile_in_zip_read_info->read_buffer;
  1527. pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis;
  1528. }
  1529. if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw))
  1530. {
  1531. uInt uDoCopy,i ;
  1532. if ((pfile_in_zip_read_info->stream.avail_in == 0) &&
  1533. (pfile_in_zip_read_info->rest_read_compressed == 0))
  1534. return (iRead==0) ? UNZ_EOF : (int)iRead;
  1535. if (pfile_in_zip_read_info->stream.avail_out <
  1536. pfile_in_zip_read_info->stream.avail_in)
  1537. uDoCopy = pfile_in_zip_read_info->stream.avail_out ;
  1538. else
  1539. uDoCopy = pfile_in_zip_read_info->stream.avail_in ;
  1540. for (i=0;i<uDoCopy;i++)
  1541. *(pfile_in_zip_read_info->stream.next_out+i) =
  1542. *(pfile_in_zip_read_info->stream.next_in+i);
  1543. pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy;
  1544. pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,
  1545. pfile_in_zip_read_info->stream.next_out,
  1546. uDoCopy);
  1547. pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy;
  1548. pfile_in_zip_read_info->stream.avail_in -= uDoCopy;
  1549. pfile_in_zip_read_info->stream.avail_out -= uDoCopy;
  1550. pfile_in_zip_read_info->stream.next_out += uDoCopy;
  1551. pfile_in_zip_read_info->stream.next_in += uDoCopy;
  1552. pfile_in_zip_read_info->stream.total_out += uDoCopy;
  1553. iRead += uDoCopy;
  1554. }
  1555. else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED)
  1556. {
  1557. #ifdef HAVE_BZIP2
  1558. uLong uTotalOutBefore,uTotalOutAfter;
  1559. const Bytef *bufBefore;
  1560. uLong uOutThis;
  1561. pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in;
  1562. pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in;
  1563. pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in;
  1564. pfile_in_zip_read_info->bstream.total_in_hi32 = 0;
  1565. pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out;
  1566. pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out;
  1567. pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out;
  1568. pfile_in_zip_read_info->bstream.total_out_hi32 = 0;
  1569. uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32;
  1570. bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out;
  1571. err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream);
  1572. uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32;
  1573. uOutThis = uTotalOutAfter-uTotalOutBefore;
  1574. pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
  1575. pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis));
  1576. pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis;
  1577. iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
  1578. pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in;
  1579. pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in;
  1580. pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32;
  1581. pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out;
  1582. pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out;
  1583. pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32;
  1584. if (err==BZ_STREAM_END)
  1585. return (iRead==0) ? UNZ_EOF : iRead;
  1586. if (err!=BZ_OK)
  1587. break;
  1588. #endif
  1589. } // end Z_BZIP2ED
  1590. else
  1591. {
  1592. ZPOS64_T uTotalOutBefore,uTotalOutAfter;
  1593. const Bytef *bufBefore;
  1594. ZPOS64_T uOutThis;
  1595. int flush=Z_SYNC_FLUSH;
  1596. uTotalOutBefore = pfile_in_zip_read_info->stream.total_out;
  1597. bufBefore = pfile_in_zip_read_info->stream.next_out;
  1598. /*
  1599. if ((pfile_in_zip_read_info->rest_read_uncompressed ==
  1600. pfile_in_zip_read_info->stream.avail_out) &&
  1601. (pfile_in_zip_read_info->rest_read_compressed == 0))
  1602. flush = Z_FINISH;
  1603. */
  1604. err=inflate(&pfile_in_zip_read_info->stream,flush);
  1605. if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL))
  1606. err = Z_DATA_ERROR;
  1607. uTotalOutAfter = pfile_in_zip_read_info->stream.total_out;
  1608. /* Detect overflow, because z_stream.total_out is uLong (32 bits) */
  1609. if (uTotalOutAfter<uTotalOutBefore)
  1610. uTotalOutAfter += 1LL << 32; /* Add maximum value of uLong + 1 */
  1611. uOutThis = uTotalOutAfter-uTotalOutBefore;
  1612. pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis;
  1613. pfile_in_zip_read_info->crc32 =
  1614. crc32(pfile_in_zip_read_info->crc32,bufBefore,
  1615. (uInt)(uOutThis));
  1616. pfile_in_zip_read_info->rest_read_uncompressed -=
  1617. uOutThis;
  1618. iRead += (uInt)(uTotalOutAfter - uTotalOutBefore);
  1619. if (err==Z_STREAM_END)
  1620. return (iRead==0) ? UNZ_EOF : (int)iRead;
  1621. if (err!=Z_OK)
  1622. break;
  1623. }
  1624. }
  1625. if (err==Z_OK)
  1626. return (int)iRead;
  1627. return err;
  1628. }
  1629. /*
  1630. Give the current position in uncompressed data
  1631. */
  1632. extern z_off_t ZEXPORT unztell (unzFile file)
  1633. {
  1634. unz64_s* s;
  1635. file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1636. if (file==NULL)
  1637. return UNZ_PARAMERROR;
  1638. s=(unz64_s*)file;
  1639. pfile_in_zip_read_info=s->pfile_in_zip_read;
  1640. if (pfile_in_zip_read_info==NULL)
  1641. return UNZ_PARAMERROR;
  1642. return (z_off_t)pfile_in_zip_read_info->stream.total_out;
  1643. }
  1644. extern ZPOS64_T ZEXPORT unztell64 (unzFile file)
  1645. {
  1646. unz64_s* s;
  1647. file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1648. if (file==NULL)
  1649. return (ZPOS64_T)-1;
  1650. s=(unz64_s*)file;
  1651. pfile_in_zip_read_info=s->pfile_in_zip_read;
  1652. if (pfile_in_zip_read_info==NULL)
  1653. return (ZPOS64_T)-1;
  1654. return pfile_in_zip_read_info->total_out_64;
  1655. }
  1656. /*
  1657. return 1 if the end of file was reached, 0 elsewhere
  1658. */
  1659. extern int ZEXPORT unzeof (unzFile file)
  1660. {
  1661. unz64_s* s;
  1662. file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1663. if (file==NULL)
  1664. return UNZ_PARAMERROR;
  1665. s=(unz64_s*)file;
  1666. pfile_in_zip_read_info=s->pfile_in_zip_read;
  1667. if (pfile_in_zip_read_info==NULL)
  1668. return UNZ_PARAMERROR;
  1669. if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
  1670. return 1;
  1671. else
  1672. return 0;
  1673. }
  1674. /*
  1675. Read extra field from the current file (opened by unzOpenCurrentFile)
  1676. This is the local-header version of the extra field (sometimes, there is
  1677. more info in the local-header version than in the central-header)
  1678. if buf==NULL, it return the size of the local extra field that can be read
  1679. if buf!=NULL, len is the size of the buffer, the extra header is copied in
  1680. buf.
  1681. the return value is the number of bytes copied in buf, or (if <0)
  1682. the error code
  1683. */
  1684. extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len)
  1685. {
  1686. unz64_s* s;
  1687. file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1688. uInt read_now;
  1689. ZPOS64_T size_to_read;
  1690. if (file==NULL)
  1691. return UNZ_PARAMERROR;
  1692. s=(unz64_s*)file;
  1693. pfile_in_zip_read_info=s->pfile_in_zip_read;
  1694. if (pfile_in_zip_read_info==NULL)
  1695. return UNZ_PARAMERROR;
  1696. size_to_read = (pfile_in_zip_read_info->size_local_extrafield -
  1697. pfile_in_zip_read_info->pos_local_extrafield);
  1698. if (buf==NULL)
  1699. return (int)size_to_read;
  1700. if (len>size_to_read)
  1701. read_now = (uInt)size_to_read;
  1702. else
  1703. read_now = (uInt)len ;
  1704. if (read_now==0)
  1705. return 0;
  1706. if (ZSEEK64(pfile_in_zip_read_info->z_filefunc,
  1707. pfile_in_zip_read_info->filestream,
  1708. pfile_in_zip_read_info->offset_local_extrafield +
  1709. pfile_in_zip_read_info->pos_local_extrafield,
  1710. ZLIB_FILEFUNC_SEEK_SET)!=0)
  1711. return UNZ_ERRNO;
  1712. if (ZREAD64(pfile_in_zip_read_info->z_filefunc,
  1713. pfile_in_zip_read_info->filestream,
  1714. buf,read_now)!=read_now)
  1715. return UNZ_ERRNO;
  1716. return (int)read_now;
  1717. }
  1718. /*
  1719. Close the file in zip opened with unzOpenCurrentFile
  1720. Return UNZ_CRCERROR if all the file was read but the CRC is not good
  1721. */
  1722. extern int ZEXPORT unzCloseCurrentFile (unzFile file)
  1723. {
  1724. int err=UNZ_OK;
  1725. unz64_s* s;
  1726. file_in_zip64_read_info_s* pfile_in_zip_read_info;
  1727. if (file==NULL)
  1728. return UNZ_PARAMERROR;
  1729. s=(unz64_s*)file;
  1730. pfile_in_zip_read_info=s->pfile_in_zip_read;
  1731. if (pfile_in_zip_read_info==NULL)
  1732. return UNZ_PARAMERROR;
  1733. if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) &&
  1734. (!pfile_in_zip_read_info->raw))
  1735. {
  1736. if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
  1737. err=UNZ_CRCERROR;
  1738. }
  1739. TRYFREE(pfile_in_zip_read_info->read_buffer);
  1740. pfile_in_zip_read_info->read_buffer = NULL;
  1741. if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED)
  1742. inflateEnd(&pfile_in_zip_read_info->stream);
  1743. #ifdef HAVE_BZIP2
  1744. else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED)
  1745. BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream);
  1746. #endif
  1747. pfile_in_zip_read_info->stream_initialised = 0;
  1748. TRYFREE(pfile_in_zip_read_info);
  1749. s->pfile_in_zip_read=NULL;
  1750. return err;
  1751. }
  1752. /*
  1753. Get the global comment string of the ZipFile, in the szComment buffer.
  1754. uSizeBuf is the size of the szComment buffer.
  1755. return the number of byte copied or an error code <0
  1756. */
  1757. extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf)
  1758. {
  1759. unz64_s* s;
  1760. uLong uReadThis ;
  1761. if (file==NULL)
  1762. return (int)UNZ_PARAMERROR;
  1763. s=(unz64_s*)file;
  1764. uReadThis = uSizeBuf;
  1765. if (uReadThis>s->gi.size_comment)
  1766. uReadThis = s->gi.size_comment;
  1767. if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0)
  1768. return UNZ_ERRNO;
  1769. if (uReadThis>0)
  1770. {
  1771. *szComment='\0';
  1772. if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis)
  1773. return UNZ_ERRNO;
  1774. }
  1775. if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment))
  1776. *(szComment+s->gi.size_comment)='\0';
  1777. return (int)uReadThis;
  1778. }
  1779. /* Additions by RX '2004 */
  1780. extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file)
  1781. {
  1782. unz64_s* s;
  1783. if (file==NULL)
  1784. return 0; //UNZ_PARAMERROR;
  1785. s=(unz64_s*)file;
  1786. if (!s->current_file_ok)
  1787. return 0;
  1788. if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff)
  1789. if (s->num_file==s->gi.number_entry)
  1790. return 0;
  1791. return s->pos_in_central_dir;
  1792. }
  1793. extern uLong ZEXPORT unzGetOffset (unzFile file)
  1794. {
  1795. ZPOS64_T offset64;
  1796. if (file==NULL)
  1797. return 0; //UNZ_PARAMERROR;
  1798. offset64 = unzGetOffset64(file);
  1799. return (uLong)offset64;
  1800. }
  1801. extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos)
  1802. {
  1803. unz64_s* s;
  1804. int err;
  1805. if (file==NULL)
  1806. return UNZ_PARAMERROR;
  1807. s=(unz64_s*)file;
  1808. s->pos_in_central_dir = pos;
  1809. s->num_file = s->gi.number_entry; /* hack */
  1810. err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info,
  1811. &s->cur_file_info_internal,
  1812. NULL,0,NULL,0,NULL,0);
  1813. s->current_file_ok = (err == UNZ_OK);
  1814. return err;
  1815. }
  1816. extern int ZEXPORT unzSetOffset (unzFile file, uLong pos)
  1817. {
  1818. return unzSetOffset64(file,pos);
  1819. }