Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

extract.c 102KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820
  1. /*
  2. Copyright (c) 1990-2009 Info-ZIP. All rights reserved.
  3. See the accompanying file LICENSE, version 2009-Jan-02 or later
  4. (the contents of which are also included in unzip.h) for terms of use.
  5. If, for some reason, all these files are missing, the Info-ZIP license
  6. also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
  7. */
  8. /*---------------------------------------------------------------------------
  9. extract.c
  10. This file contains the high-level routines ("driver routines") for extrac-
  11. ting and testing zipfile members. It calls the low-level routines in files
  12. explode.c, inflate.c, unreduce.c and unshrink.c.
  13. Contains: extract_or_test_files()
  14. store_info()
  15. find_compr_idx()
  16. extract_or_test_entrylist()
  17. extract_or_test_member()
  18. TestExtraField()
  19. test_compr_eb()
  20. memextract()
  21. memflush()
  22. extract_izvms_block() (VMS or VMS_TEXT_CONV)
  23. set_deferred_symlink() (SYMLINKS only)
  24. fnfilter()
  25. dircomp() (SET_DIR_ATTRIB only)
  26. UZbunzip2() (USE_BZIP2 only)
  27. ---------------------------------------------------------------------------*/
  28. #define __EXTRACT_C /* identifies this source module */
  29. #define UNZIP_INTERNAL
  30. #include "unzip.h"
  31. #ifdef WINDLL
  32. # ifdef POCKET_UNZIP
  33. # include "wince/intrface.h"
  34. # else
  35. # include "windll/windll.h"
  36. # endif
  37. #endif
  38. #include "crc32.h"
  39. #include "crypt.h"
  40. #define GRRDUMP(buf,len) { \
  41. int i, j; \
  42. \
  43. for (j = 0; j < (len)/16; ++j) { \
  44. printf(" "); \
  45. for (i = 0; i < 16; ++i) \
  46. printf("%02x ", (uch)(buf)[i+(j<<4)]); \
  47. printf("\n "); \
  48. for (i = 0; i < 16; ++i) { \
  49. char c = (char)(buf)[i+(j<<4)]; \
  50. \
  51. if (c == '\n') \
  52. printf("\\n "); \
  53. else if (c == '\r') \
  54. printf("\\r "); \
  55. else \
  56. printf(" %c ", c); \
  57. } \
  58. printf("\n"); \
  59. } \
  60. if ((len) % 16) { \
  61. printf(" "); \
  62. for (i = j<<4; i < (len); ++i) \
  63. printf("%02x ", (uch)(buf)[i]); \
  64. printf("\n "); \
  65. for (i = j<<4; i < (len); ++i) { \
  66. char c = (char)(buf)[i]; \
  67. \
  68. if (c == '\n') \
  69. printf("\\n "); \
  70. else if (c == '\r') \
  71. printf("\\r "); \
  72. else \
  73. printf(" %c ", c); \
  74. } \
  75. printf("\n"); \
  76. } \
  77. }
  78. static int store_info OF((__GPRO));
  79. #ifdef SET_DIR_ATTRIB
  80. static int extract_or_test_entrylist OF((__GPRO__ unsigned numchunk,
  81. ulg *pfilnum, ulg *pnum_bad_pwd, zoff_t *pold_extra_bytes,
  82. unsigned *pnum_dirs, direntry **pdirlist,
  83. int error_in_archive));
  84. #else
  85. static int extract_or_test_entrylist OF((__GPRO__ unsigned numchunk,
  86. ulg *pfilnum, ulg *pnum_bad_pwd, zoff_t *pold_extra_bytes,
  87. int error_in_archive));
  88. #endif
  89. static int extract_or_test_member OF((__GPRO));
  90. #ifndef SFX
  91. static int TestExtraField OF((__GPRO__ uch *ef, unsigned ef_len));
  92. static int test_compr_eb OF((__GPRO__ uch *eb, unsigned eb_size,
  93. unsigned compr_offset,
  94. int (*test_uc_ebdata)(__GPRO__ uch *eb, unsigned eb_size,
  95. uch *eb_ucptr, ulg eb_ucsize)));
  96. #endif
  97. #if (defined(VMS) || defined(VMS_TEXT_CONV))
  98. static void decompress_bits OF((uch *outptr, unsigned needlen,
  99. ZCONST uch *bitptr));
  100. #endif
  101. #ifdef SYMLINKS
  102. static void set_deferred_symlink OF((__GPRO__ slinkentry *slnk_entry));
  103. #endif
  104. #ifdef SET_DIR_ATTRIB
  105. static int Cdecl dircomp OF((ZCONST zvoid *a, ZCONST zvoid *b));
  106. #endif
  107. /*******************************/
  108. /* Strings used in extract.c */
  109. /*******************************/
  110. static ZCONST char Far VersionMsg[] =
  111. " skipping: %-22s need %s compat. v%u.%u (can do v%u.%u)\n";
  112. static ZCONST char Far ComprMsgNum[] =
  113. " skipping: %-22s unsupported compression method %u\n";
  114. #ifndef SFX
  115. static ZCONST char Far ComprMsgName[] =
  116. " skipping: %-22s `%s' method not supported\n";
  117. static ZCONST char Far CmprNone[] = "store";
  118. static ZCONST char Far CmprShrink[] = "shrink";
  119. static ZCONST char Far CmprReduce[] = "reduce";
  120. static ZCONST char Far CmprImplode[] = "implode";
  121. static ZCONST char Far CmprTokenize[] = "tokenize";
  122. static ZCONST char Far CmprDeflate[] = "deflate";
  123. static ZCONST char Far CmprDeflat64[] = "deflate64";
  124. static ZCONST char Far CmprDCLImplode[] = "DCL implode";
  125. static ZCONST char Far CmprBzip[] = "bzip2";
  126. static ZCONST char Far CmprLZMA[] = "LZMA";
  127. static ZCONST char Far CmprIBMTerse[] = "IBM/Terse";
  128. static ZCONST char Far CmprIBMLZ77[] = "IBM LZ77";
  129. static ZCONST char Far CmprWavPack[] = "WavPack";
  130. static ZCONST char Far CmprPPMd[] = "PPMd";
  131. static ZCONST char Far *ComprNames[NUM_METHODS] = {
  132. CmprNone, CmprShrink, CmprReduce, CmprReduce, CmprReduce, CmprReduce,
  133. CmprImplode, CmprTokenize, CmprDeflate, CmprDeflat64, CmprDCLImplode,
  134. CmprBzip, CmprLZMA, CmprIBMTerse, CmprIBMLZ77, CmprWavPack, CmprPPMd
  135. };
  136. static ZCONST unsigned ComprIDs[NUM_METHODS] = {
  137. STORED, SHRUNK, REDUCED1, REDUCED2, REDUCED3, REDUCED4,
  138. IMPLODED, TOKENIZED, DEFLATED, ENHDEFLATED, DCLIMPLODED,
  139. BZIPPED, LZMAED, IBMTERSED, IBMLZ77ED, WAVPACKED, PPMDED
  140. };
  141. #endif /* !SFX */
  142. static ZCONST char Far FilNamMsg[] =
  143. "%s: bad filename length (%s)\n";
  144. #ifndef SFX
  145. static ZCONST char Far WarnNoMemCFName[] =
  146. "%s: warning, no memory for comparison with local header\n";
  147. static ZCONST char Far LvsCFNamMsg[] =
  148. "%s: mismatching \"local\" filename (%s),\n\
  149. continuing with \"central\" filename version\n";
  150. #endif /* !SFX */
  151. #if (!defined(SFX) && defined(UNICODE_SUPPORT))
  152. static ZCONST char Far GP11FlagsDiffer[] =
  153. "file #%lu (%s):\n\
  154. mismatch between local and central GPF bit 11 (\"UTF-8\"),\n\
  155. continuing with central flag (IsUTF8 = %d)\n";
  156. #endif /* !SFX && UNICODE_SUPPORT */
  157. static ZCONST char Far WrnStorUCSizCSizDiff[] =
  158. "%s: ucsize %s <> csize %s for STORED entry\n\
  159. continuing with \"compressed\" size value\n";
  160. static ZCONST char Far ExtFieldMsg[] =
  161. "%s: bad extra field length (%s)\n";
  162. static ZCONST char Far OffsetMsg[] =
  163. "file #%lu: bad zipfile offset (%s): %ld\n";
  164. static ZCONST char Far ExtractMsg[] =
  165. "%8sing: %-22s %s%s";
  166. #ifndef SFX
  167. static ZCONST char Far LengthMsg[] =
  168. "%s %s: %s bytes required to uncompress to %s bytes;\n %s\
  169. supposed to require %s bytes%s%s%s\n";
  170. #endif
  171. static ZCONST char Far BadFileCommLength[] = "%s: bad file comment length\n";
  172. static ZCONST char Far LocalHdrSig[] = "local header sig";
  173. static ZCONST char Far BadLocalHdr[] = "file #%lu: bad local header\n";
  174. static ZCONST char Far AttemptRecompensate[] =
  175. " (attempting to re-compensate)\n";
  176. #ifndef SFX
  177. static ZCONST char Far BackslashPathSep[] =
  178. "warning: %s appears to use backslashes as path separators\n";
  179. #endif
  180. static ZCONST char Far AbsolutePathWarning[] =
  181. "warning: stripped absolute path spec from %s\n";
  182. static ZCONST char Far SkipVolumeLabel[] =
  183. " skipping: %-22s %svolume label\n";
  184. #ifdef SET_DIR_ATTRIB /* messages of code for setting directory attributes */
  185. static ZCONST char Far DirlistEntryNoMem[] =
  186. "warning: cannot alloc memory for dir times/permissions/UID/GID\n";
  187. static ZCONST char Far DirlistSortNoMem[] =
  188. "warning: cannot alloc memory to sort dir times/perms/etc.\n";
  189. static ZCONST char Far DirlistSetAttrFailed[] =
  190. "warning: set times/attribs failed for %s\n";
  191. static ZCONST char Far DirlistFailAttrSum[] =
  192. " failed setting times/attribs for %lu dir entries";
  193. #endif
  194. #ifdef SYMLINKS /* messages of the deferred symlinks handler */
  195. static ZCONST char Far SymLnkWarnNoMem[] =
  196. "warning: deferred symlink (%s) failed:\n\
  197. out of memory\n";
  198. static ZCONST char Far SymLnkWarnInvalid[] =
  199. "warning: deferred symlink (%s) failed:\n\
  200. invalid placeholder file\n";
  201. static ZCONST char Far SymLnkDeferred[] =
  202. "finishing deferred symbolic links:\n";
  203. static ZCONST char Far SymLnkFinish[] =
  204. " %-22s -> %s\n";
  205. #endif
  206. #ifndef WINDLL
  207. static ZCONST char Far ReplaceQuery[] =
  208. # ifdef VMS
  209. "new version of %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ";
  210. # else
  211. "replace %s? [y]es, [n]o, [A]ll, [N]one, [r]ename: ";
  212. # endif
  213. static ZCONST char Far AssumeNone[] =
  214. " NULL\n(EOF or read error, treating as \"[N]one\" ...)\n";
  215. static ZCONST char Far NewNameQuery[] = "new name: ";
  216. static ZCONST char Far InvalidResponse[] =
  217. "error: invalid response [%s]\n";
  218. #endif /* !WINDLL */
  219. static ZCONST char Far ErrorInArchive[] =
  220. "At least one %serror was detected in %s.\n";
  221. static ZCONST char Far ZeroFilesTested[] =
  222. "Caution: zero files tested in %s.\n";
  223. #ifndef VMS
  224. static ZCONST char Far VMSFormatQuery[] =
  225. "\n%s: stored in VMS format. Extract anyway? (y/n) ";
  226. #endif
  227. #if CRYPT
  228. static ZCONST char Far SkipCannotGetPasswd[] =
  229. " skipping: %-22s unable to get password\n";
  230. static ZCONST char Far SkipIncorrectPasswd[] =
  231. " skipping: %-22s incorrect password\n";
  232. static ZCONST char Far FilesSkipBadPasswd[] =
  233. "%lu file%s skipped because of incorrect password.\n";
  234. static ZCONST char Far MaybeBadPasswd[] =
  235. " (may instead be incorrect password)\n";
  236. #else
  237. static ZCONST char Far SkipEncrypted[] =
  238. " skipping: %-22s encrypted (not supported)\n";
  239. #endif
  240. static ZCONST char Far NoErrInCompData[] =
  241. "No errors detected in compressed data of %s.\n";
  242. static ZCONST char Far NoErrInTestedFiles[] =
  243. "No errors detected in %s for the %lu file%s tested.\n";
  244. static ZCONST char Far FilesSkipped[] =
  245. "%lu file%s skipped because of unsupported compression or encoding.\n";
  246. static ZCONST char Far ErrUnzipFile[] = " error: %s%s %s\n";
  247. static ZCONST char Far ErrUnzipNoFile[] = "\n error: %s%s\n";
  248. static ZCONST char Far NotEnoughMem[] = "not enough memory to ";
  249. static ZCONST char Far InvalidComprData[] = "invalid compressed data to ";
  250. static ZCONST char Far Inflate[] = "inflate";
  251. #ifdef USE_BZIP2
  252. static ZCONST char Far BUnzip[] = "bunzip";
  253. #endif
  254. #ifndef SFX
  255. static ZCONST char Far Explode[] = "explode";
  256. #ifndef LZW_CLEAN
  257. static ZCONST char Far Unshrink[] = "unshrink";
  258. #endif
  259. #endif
  260. #if (!defined(DELETE_IF_FULL) || !defined(HAVE_UNLINK))
  261. static ZCONST char Far FileTruncated[] =
  262. "warning: %s is probably truncated\n";
  263. #endif
  264. static ZCONST char Far FileUnknownCompMethod[] =
  265. "%s: unknown compression method\n";
  266. static ZCONST char Far BadCRC[] = " bad CRC %08lx (should be %08lx)\n";
  267. /* TruncEAs[] also used in OS/2 mapname(), close_outfile() */
  268. char ZCONST Far TruncEAs[] = " compressed EA data missing (%d bytes)%s";
  269. char ZCONST Far TruncNTSD[] =
  270. " compressed WinNT security data missing (%d bytes)%s";
  271. #ifndef SFX
  272. static ZCONST char Far InconsistEFlength[] = "bad extra-field entry:\n \
  273. EF block length (%u bytes) exceeds remaining EF data (%u bytes)\n";
  274. static ZCONST char Far InvalidComprDataEAs[] =
  275. " invalid compressed data for EAs\n";
  276. # if (defined(WIN32) && defined(NTSD_EAS))
  277. static ZCONST char Far InvalidSecurityEAs[] =
  278. " EAs fail security check\n";
  279. # endif
  280. static ZCONST char Far UnsuppNTSDVersEAs[] =
  281. " unsupported NTSD EAs version %d\n";
  282. static ZCONST char Far BadCRC_EAs[] = " bad CRC for extended attributes\n";
  283. static ZCONST char Far UnknComprMethodEAs[] =
  284. " unknown compression method for EAs (%u)\n";
  285. static ZCONST char Far NotEnoughMemEAs[] =
  286. " out of memory while inflating EAs\n";
  287. static ZCONST char Far UnknErrorEAs[] =
  288. " unknown error on extended attributes\n";
  289. #endif /* !SFX */
  290. static ZCONST char Far UnsupportedExtraField[] =
  291. "\nerror: unsupported extra-field compression type (%u)--skipping\n";
  292. static ZCONST char Far BadExtraFieldCRC[] =
  293. "error [%s]: bad extra-field CRC %08lx (should be %08lx)\n";
  294. /**************************************/
  295. /* Function extract_or_test_files() */
  296. /**************************************/
  297. int extract_or_test_files(__G) /* return PK-type error code */
  298. __GDEF
  299. {
  300. unsigned i, j;
  301. zoff_t cd_bufstart;
  302. uch *cd_inptr;
  303. int cd_incnt;
  304. ulg filnum=0L, blknum=0L;
  305. int reached_end;
  306. #ifndef SFX
  307. int no_endsig_found;
  308. #endif
  309. int error, error_in_archive=PK_COOL;
  310. int *fn_matched=NULL, *xn_matched=NULL;
  311. zucn_t members_processed;
  312. ulg num_skipped=0L, num_bad_pwd=0L;
  313. zoff_t old_extra_bytes = 0L;
  314. #ifdef SET_DIR_ATTRIB
  315. unsigned num_dirs=0;
  316. direntry *dirlist=(direntry *)NULL, **sorted_dirlist=(direntry **)NULL;
  317. #endif
  318. /*
  319. * First, two general initializations are applied. These have been moved
  320. * here from process_zipfiles() because they are only needed for accessing
  321. * and/or extracting the data content of the zip archive.
  322. */
  323. /* a) initialize the CRC table pointer (once) */
  324. if (CRC_32_TAB == NULL) {
  325. if ((CRC_32_TAB = get_crc_table()) == NULL) {
  326. return PK_MEM;
  327. }
  328. }
  329. #if (!defined(SFX) || defined(SFX_EXDIR))
  330. /* b) check out if specified extraction root directory exists */
  331. if (uO.exdir != (char *)NULL && G.extract_flag) {
  332. G.create_dirs = !uO.fflag;
  333. if ((error = checkdir(__G__ uO.exdir, ROOT)) > MPN_INF_SKIP) {
  334. /* out of memory, or file in way */
  335. return (error == MPN_NOMEM ? PK_MEM : PK_ERR);
  336. }
  337. }
  338. #endif /* !SFX || SFX_EXDIR */
  339. /*---------------------------------------------------------------------------
  340. The basic idea of this function is as follows. Since the central di-
  341. rectory lies at the end of the zipfile and the member files lie at the
  342. beginning or middle or wherever, it is not very desirable to simply
  343. read a central directory entry, jump to the member and extract it, and
  344. then jump back to the central directory. In the case of a large zipfile
  345. this would lead to a whole lot of disk-grinding, especially if each mem-
  346. ber file is small. Instead, we read from the central directory the per-
  347. tinent information for a block of files, then go extract/test the whole
  348. block. Thus this routine contains two small(er) loops within a very
  349. large outer loop: the first of the small ones reads a block of files
  350. from the central directory; the second extracts or tests each file; and
  351. the outer one loops over blocks. There's some file-pointer positioning
  352. stuff in between, but that's about it. Btw, it's because of this jump-
  353. ing around that we can afford to be lenient if an error occurs in one of
  354. the member files: we should still be able to go find the other members,
  355. since we know the offset of each from the beginning of the zipfile.
  356. ---------------------------------------------------------------------------*/
  357. G.pInfo = G.info;
  358. #if CRYPT
  359. G.newzip = TRUE;
  360. #endif
  361. #ifndef SFX
  362. G.reported_backslash = FALSE;
  363. #endif
  364. /* malloc space for check on unmatched filespecs (OK if one or both NULL) */
  365. if (G.filespecs > 0 &&
  366. (fn_matched=(int *)malloc(G.filespecs*sizeof(int))) != (int *)NULL)
  367. for (i = 0; i < G.filespecs; ++i)
  368. fn_matched[i] = FALSE;
  369. if (G.xfilespecs > 0 &&
  370. (xn_matched=(int *)malloc(G.xfilespecs*sizeof(int))) != (int *)NULL)
  371. for (i = 0; i < G.xfilespecs; ++i)
  372. xn_matched[i] = FALSE;
  373. /*---------------------------------------------------------------------------
  374. Begin main loop over blocks of member files. We know the entire central
  375. directory is on this disk: we would not have any of this information un-
  376. less the end-of-central-directory record was on this disk, and we would
  377. not have gotten to this routine unless this is also the disk on which
  378. the central directory starts. In practice, this had better be the ONLY
  379. disk in the archive, but we'll add multi-disk support soon.
  380. ---------------------------------------------------------------------------*/
  381. members_processed = 0;
  382. #ifndef SFX
  383. no_endsig_found = FALSE;
  384. #endif
  385. reached_end = FALSE;
  386. while (!reached_end) {
  387. j = 0;
  388. #ifdef AMIGA
  389. memzero(G.filenotes, DIR_BLKSIZ * sizeof(char *));
  390. #endif
  391. /*
  392. * Loop through files in central directory, storing offsets, file
  393. * attributes, case-conversion and text-conversion flags until block
  394. * size is reached.
  395. */
  396. while ((j < DIR_BLKSIZ)) {
  397. G.pInfo = &G.info[j];
  398. if (readbuf(__G__ G.sig, 4) == 0) {
  399. error_in_archive = PK_EOF;
  400. reached_end = TRUE; /* ...so no more left to do */
  401. break;
  402. }
  403. if (memcmp(G.sig, central_hdr_sig, 4)) { /* is it a new entry? */
  404. /* no new central directory entry
  405. * -> is the number of processed entries compatible with the
  406. * number of entries as stored in the end_central record?
  407. */
  408. if ((members_processed
  409. & (G.ecrec.have_ecr64 ? MASK_ZUCN64 : MASK_ZUCN16))
  410. == G.ecrec.total_entries_central_dir) {
  411. #ifndef SFX
  412. /* yes, so look if we ARE back at the end_central record
  413. */
  414. no_endsig_found =
  415. ( (memcmp(G.sig,
  416. (G.ecrec.have_ecr64 ?
  417. end_central64_sig : end_central_sig),
  418. 4) != 0)
  419. && (!G.ecrec.is_zip64_archive)
  420. && (memcmp(G.sig, end_central_sig, 4) != 0)
  421. );
  422. #endif /* !SFX */
  423. } else {
  424. /* no; we have found an error in the central directory
  425. * -> report it and stop searching for more Zip entries
  426. */
  427. Info(slide, 0x401, ((char *)slide,
  428. LoadFarString(CentSigMsg), j + blknum*DIR_BLKSIZ + 1));
  429. Info(slide, 0x401, ((char *)slide,
  430. LoadFarString(ReportMsg)));
  431. error_in_archive = PK_BADERR;
  432. }
  433. reached_end = TRUE; /* ...so no more left to do */
  434. break;
  435. }
  436. /* process_cdir_file_hdr() sets pInfo->hostnum, pInfo->lcflag */
  437. if ((error = process_cdir_file_hdr(__G)) != PK_COOL) {
  438. error_in_archive = error; /* only PK_EOF defined */
  439. reached_end = TRUE; /* ...so no more left to do */
  440. break;
  441. }
  442. if ((error = do_string(__G__ G.crec.filename_length, DS_FN)) !=
  443. PK_COOL)
  444. {
  445. if (error > error_in_archive)
  446. error_in_archive = error;
  447. if (error > PK_WARN) { /* fatal: no more left to do */
  448. Info(slide, 0x401, ((char *)slide,
  449. LoadFarString(FilNamMsg),
  450. FnFilter1(G.filename), "central"));
  451. reached_end = TRUE;
  452. break;
  453. }
  454. }
  455. if ((error = do_string(__G__ G.crec.extra_field_length,
  456. EXTRA_FIELD)) != 0)
  457. {
  458. if (error > error_in_archive)
  459. error_in_archive = error;
  460. if (error > PK_WARN) { /* fatal */
  461. Info(slide, 0x401, ((char *)slide,
  462. LoadFarString(ExtFieldMsg),
  463. FnFilter1(G.filename), "central"));
  464. reached_end = TRUE;
  465. break;
  466. }
  467. }
  468. #ifdef AMIGA
  469. G.filenote_slot = j;
  470. if ((error = do_string(__G__ G.crec.file_comment_length,
  471. uO.N_flag ? FILENOTE : SKIP)) != PK_COOL)
  472. #else
  473. if ((error = do_string(__G__ G.crec.file_comment_length, SKIP))
  474. != PK_COOL)
  475. #endif
  476. {
  477. if (error > error_in_archive)
  478. error_in_archive = error;
  479. if (error > PK_WARN) { /* fatal */
  480. Info(slide, 0x421, ((char *)slide,
  481. LoadFarString(BadFileCommLength),
  482. FnFilter1(G.filename)));
  483. reached_end = TRUE;
  484. break;
  485. }
  486. }
  487. if (G.process_all_files) {
  488. if (store_info(__G))
  489. ++j; /* file is OK; info[] stored; continue with next */
  490. else
  491. ++num_skipped;
  492. } else {
  493. int do_this_file;
  494. if (G.filespecs == 0)
  495. do_this_file = TRUE;
  496. else { /* check if this entry matches an `include' argument */
  497. do_this_file = FALSE;
  498. for (i = 0; i < G.filespecs; i++)
  499. if (match(G.filename, G.pfnames[i], uO.C_flag WISEP)) {
  500. do_this_file = TRUE; /* ^-- ignore case or not? */
  501. if (fn_matched)
  502. fn_matched[i] = TRUE;
  503. break; /* found match, so stop looping */
  504. }
  505. }
  506. if (do_this_file) { /* check if this is an excluded file */
  507. for (i = 0; i < G.xfilespecs; i++)
  508. if (match(G.filename, G.pxnames[i], uO.C_flag WISEP)) {
  509. do_this_file = FALSE; /* ^-- ignore case or not? */
  510. if (xn_matched)
  511. xn_matched[i] = TRUE;
  512. break;
  513. }
  514. }
  515. if (do_this_file) {
  516. if (store_info(__G))
  517. ++j; /* file is OK */
  518. else
  519. ++num_skipped; /* unsupp. compression or encryption */
  520. }
  521. } /* end if (process_all_files) */
  522. members_processed++;
  523. } /* end while-loop (adding files to current block) */
  524. /* save position in central directory so can come back later */
  525. cd_bufstart = G.cur_zipfile_bufstart;
  526. cd_inptr = G.inptr;
  527. cd_incnt = G.incnt;
  528. /*-----------------------------------------------------------------------
  529. Second loop: process files in current block, extracting or testing
  530. each one.
  531. -----------------------------------------------------------------------*/
  532. error = extract_or_test_entrylist(__G__ j,
  533. &filnum, &num_bad_pwd, &old_extra_bytes,
  534. #ifdef SET_DIR_ATTRIB
  535. &num_dirs, &dirlist,
  536. #endif
  537. error_in_archive);
  538. if (error != PK_COOL) {
  539. if (error > error_in_archive)
  540. error_in_archive = error;
  541. /* ...and keep going (unless disk full or user break) */
  542. if (G.disk_full > 1 || error_in_archive == IZ_CTRLC) {
  543. /* clear reached_end to signal premature stop ... */
  544. reached_end = FALSE;
  545. /* ... and cancel scanning the central directory */
  546. break;
  547. }
  548. }
  549. /*
  550. * Jump back to where we were in the central directory, then go and do
  551. * the next batch of files.
  552. */
  553. #ifdef USE_STRM_INPUT
  554. zfseeko(G.zipfd, cd_bufstart, SEEK_SET);
  555. G.cur_zipfile_bufstart = zftello(G.zipfd);
  556. #else /* !USE_STRM_INPUT */
  557. G.cur_zipfile_bufstart =
  558. zlseek(G.zipfd, cd_bufstart, SEEK_SET);
  559. #endif /* ?USE_STRM_INPUT */
  560. read(G.zipfd, (char *)G.inbuf, INBUFSIZ); /* been here before... */
  561. G.inptr = cd_inptr;
  562. G.incnt = cd_incnt;
  563. ++blknum;
  564. #ifdef TEST
  565. printf("\ncd_bufstart = %ld (%.8lXh)\n", cd_bufstart, cd_bufstart);
  566. printf("cur_zipfile_bufstart = %ld (%.8lXh)\n", cur_zipfile_bufstart,
  567. cur_zipfile_bufstart);
  568. printf("inptr-inbuf = %d\n", G.inptr-G.inbuf);
  569. printf("incnt = %d\n\n", G.incnt);
  570. #endif
  571. } /* end while-loop (blocks of files in central directory) */
  572. /*---------------------------------------------------------------------------
  573. Process the list of deferred symlink extractions and finish up
  574. the symbolic links.
  575. ---------------------------------------------------------------------------*/
  576. #ifdef SYMLINKS
  577. if (G.slink_last != NULL) {
  578. if (QCOND2)
  579. Info(slide, 0, ((char *)slide, LoadFarString(SymLnkDeferred)));
  580. while (G.slink_head != NULL) {
  581. set_deferred_symlink(__G__ G.slink_head);
  582. /* remove the processed entry from the chain and free its memory */
  583. G.slink_last = G.slink_head;
  584. G.slink_head = G.slink_last->next;
  585. free(G.slink_last);
  586. }
  587. G.slink_last = NULL;
  588. }
  589. #endif /* SYMLINKS */
  590. /*---------------------------------------------------------------------------
  591. Go back through saved list of directories, sort and set times/perms/UIDs
  592. and GIDs from the deepest level on up.
  593. ---------------------------------------------------------------------------*/
  594. #ifdef SET_DIR_ATTRIB
  595. if (num_dirs > 0) {
  596. sorted_dirlist = (direntry **)malloc(num_dirs*sizeof(direntry *));
  597. if (sorted_dirlist == (direntry **)NULL) {
  598. Info(slide, 0x401, ((char *)slide,
  599. LoadFarString(DirlistSortNoMem)));
  600. while (dirlist != (direntry *)NULL) {
  601. direntry *d = dirlist;
  602. dirlist = dirlist->next;
  603. free(d);
  604. }
  605. } else {
  606. ulg ndirs_fail = 0;
  607. if (num_dirs == 1)
  608. sorted_dirlist[0] = dirlist;
  609. else {
  610. for (i = 0; i < num_dirs; ++i) {
  611. sorted_dirlist[i] = dirlist;
  612. dirlist = dirlist->next;
  613. }
  614. qsort((char *)sorted_dirlist, num_dirs, sizeof(direntry *),
  615. dircomp);
  616. }
  617. Trace((stderr, "setting directory times/perms/attributes\n"));
  618. for (i = 0; i < num_dirs; ++i) {
  619. direntry *d = sorted_dirlist[i];
  620. Trace((stderr, "dir = %s\n", d->fn));
  621. if ((error = set_direc_attribs(__G__ d)) != PK_OK) {
  622. ndirs_fail++;
  623. Info(slide, 0x201, ((char *)slide,
  624. LoadFarString(DirlistSetAttrFailed), d->fn));
  625. if (!error_in_archive)
  626. error_in_archive = error;
  627. }
  628. free(d);
  629. }
  630. free(sorted_dirlist);
  631. if (!uO.tflag && QCOND2) {
  632. if (ndirs_fail > 0)
  633. Info(slide, 0, ((char *)slide,
  634. LoadFarString(DirlistFailAttrSum), ndirs_fail));
  635. }
  636. }
  637. }
  638. #endif /* SET_DIR_ATTRIB */
  639. /*---------------------------------------------------------------------------
  640. Check for unmatched filespecs on command line and print warning if any
  641. found. Free allocated memory. (But suppress check when central dir
  642. scan was interrupted prematurely.)
  643. ---------------------------------------------------------------------------*/
  644. if (fn_matched) {
  645. if (reached_end) for (i = 0; i < G.filespecs; ++i)
  646. if (!fn_matched[i]) {
  647. #ifdef DLL
  648. if (!G.redirect_data && !G.redirect_text)
  649. Info(slide, 0x401, ((char *)slide,
  650. LoadFarString(FilenameNotMatched), G.pfnames[i]));
  651. else
  652. setFileNotFound(__G);
  653. #else
  654. Info(slide, 1, ((char *)slide,
  655. LoadFarString(FilenameNotMatched), G.pfnames[i]));
  656. #endif
  657. if (error_in_archive <= PK_WARN)
  658. error_in_archive = PK_FIND; /* some files not found */
  659. }
  660. free((zvoid *)fn_matched);
  661. }
  662. if (xn_matched) {
  663. if (reached_end) for (i = 0; i < G.xfilespecs; ++i)
  664. if (!xn_matched[i])
  665. Info(slide, 0x401, ((char *)slide,
  666. LoadFarString(ExclFilenameNotMatched), G.pxnames[i]));
  667. free((zvoid *)xn_matched);
  668. }
  669. /*---------------------------------------------------------------------------
  670. Now, all locally allocated memory has been released. When the central
  671. directory processing has been interrupted prematurely, it is safe to
  672. return immediately. All completeness checks and summary messages are
  673. skipped in this case.
  674. ---------------------------------------------------------------------------*/
  675. if (!reached_end)
  676. return error_in_archive;
  677. /*---------------------------------------------------------------------------
  678. Double-check that we're back at the end-of-central-directory record, and
  679. print quick summary of results, if we were just testing the archive. We
  680. send the summary to stdout so that people doing the testing in the back-
  681. ground and redirecting to a file can just do a "tail" on the output file.
  682. ---------------------------------------------------------------------------*/
  683. #ifndef SFX
  684. if (no_endsig_found) { /* just to make sure */
  685. Info(slide, 0x401, ((char *)slide, LoadFarString(EndSigMsg)));
  686. Info(slide, 0x401, ((char *)slide, LoadFarString(ReportMsg)));
  687. if (!error_in_archive) /* don't overwrite stronger error */
  688. error_in_archive = PK_WARN;
  689. }
  690. #endif /* !SFX */
  691. if (uO.tflag) {
  692. ulg num = filnum - num_bad_pwd;
  693. if (uO.qflag < 2) { /* GRR 930710: was (uO.qflag == 1) */
  694. if (error_in_archive)
  695. Info(slide, 0, ((char *)slide, LoadFarString(ErrorInArchive),
  696. (error_in_archive == PK_WARN)? "warning-" : "", G.zipfn));
  697. else if (num == 0L)
  698. Info(slide, 0, ((char *)slide, LoadFarString(ZeroFilesTested),
  699. G.zipfn));
  700. else if (G.process_all_files && (num_skipped+num_bad_pwd == 0L))
  701. Info(slide, 0, ((char *)slide, LoadFarString(NoErrInCompData),
  702. G.zipfn));
  703. else
  704. Info(slide, 0, ((char *)slide, LoadFarString(NoErrInTestedFiles)
  705. , G.zipfn, num, (num==1L)? "":"s"));
  706. if (num_skipped > 0L)
  707. Info(slide, 0, ((char *)slide, LoadFarString(FilesSkipped),
  708. num_skipped, (num_skipped==1L)? "":"s"));
  709. #if CRYPT
  710. if (num_bad_pwd > 0L)
  711. Info(slide, 0, ((char *)slide, LoadFarString(FilesSkipBadPasswd)
  712. , num_bad_pwd, (num_bad_pwd==1L)? "":"s"));
  713. #endif /* CRYPT */
  714. }
  715. }
  716. /* give warning if files not tested or extracted (first condition can still
  717. * happen if zipfile is empty and no files specified on command line) */
  718. if ((filnum == 0) && error_in_archive <= PK_WARN) {
  719. if (num_skipped > 0L)
  720. error_in_archive = IZ_UNSUP; /* unsupport. compression/encryption */
  721. else
  722. error_in_archive = PK_FIND; /* no files found at all */
  723. }
  724. #if CRYPT
  725. else if ((filnum == num_bad_pwd) && error_in_archive <= PK_WARN)
  726. error_in_archive = IZ_BADPWD; /* bad passwd => all files skipped */
  727. #endif
  728. else if ((num_skipped > 0L) && error_in_archive <= PK_WARN)
  729. error_in_archive = IZ_UNSUP; /* was PK_WARN; Jean-loup complained */
  730. #if CRYPT
  731. else if ((num_bad_pwd > 0L) && !error_in_archive)
  732. error_in_archive = PK_WARN;
  733. #endif
  734. return error_in_archive;
  735. } /* end function extract_or_test_files() */
  736. /***************************/
  737. /* Function store_info() */
  738. /***************************/
  739. static int store_info(__G) /* return 0 if skipping, 1 if OK */
  740. __GDEF
  741. {
  742. #ifdef USE_BZIP2
  743. # define UNKN_BZ2 (G.crec.compression_method!=BZIPPED)
  744. #else
  745. # define UNKN_BZ2 TRUE /* bzip2 unknown */
  746. #endif
  747. #ifdef USE_LZMA
  748. # define UNKN_LZMA (G.crec.compression_method!=LZMAED)
  749. #else
  750. # define UNKN_LZMA TRUE /* LZMA unknown */
  751. #endif
  752. #ifdef USE_WAVP
  753. # define UNKN_WAVP (G.crec.compression_method!=WAVPACKED)
  754. #else
  755. # define UNKN_WAVP TRUE /* WavPack unknown */
  756. #endif
  757. #ifdef USE_PPMD
  758. # define UNKN_PPMD (G.crec.compression_method!=PPMDED)
  759. #else
  760. # define UNKN_PPMD TRUE /* PPMd unknown */
  761. #endif
  762. #ifdef SFX
  763. # ifdef USE_DEFLATE64
  764. # define UNKN_COMPR \
  765. (G.crec.compression_method!=STORED && G.crec.compression_method<DEFLATED \
  766. && G.crec.compression_method>ENHDEFLATED \
  767. && UNKN_BZ2 && UNKN_LZMA && UNKN_WAVP && UNKN_PPMD)
  768. # else
  769. # define UNKN_COMPR \
  770. (G.crec.compression_method!=STORED && G.crec.compression_method!=DEFLATED\
  771. && UNKN_BZ2 && UNKN_LZMA && UNKN_WAVP && UNKN_PPMD)
  772. # endif
  773. #else
  774. # ifdef COPYRIGHT_CLEAN /* no reduced files */
  775. # define UNKN_RED (G.crec.compression_method >= REDUCED1 && \
  776. G.crec.compression_method <= REDUCED4)
  777. # else
  778. # define UNKN_RED FALSE /* reducing not unknown */
  779. # endif
  780. # ifdef LZW_CLEAN /* no shrunk files */
  781. # define UNKN_SHR (G.crec.compression_method == SHRUNK)
  782. # else
  783. # define UNKN_SHR FALSE /* unshrinking not unknown */
  784. # endif
  785. # ifdef USE_DEFLATE64
  786. # define UNKN_COMPR (UNKN_RED || UNKN_SHR || \
  787. G.crec.compression_method==TOKENIZED || \
  788. (G.crec.compression_method>ENHDEFLATED && UNKN_BZ2 && UNKN_LZMA \
  789. && UNKN_WAVP && UNKN_PPMD))
  790. # else
  791. # define UNKN_COMPR (UNKN_RED || UNKN_SHR || \
  792. G.crec.compression_method==TOKENIZED || \
  793. (G.crec.compression_method>DEFLATED && UNKN_BZ2 && UNKN_LZMA \
  794. && UNKN_WAVP && UNKN_PPMD))
  795. # endif
  796. #endif
  797. #if (defined(USE_BZIP2) && (UNZIP_VERSION < UNZIP_BZ2VERS))
  798. int unzvers_support = (UNKN_BZ2 ? UNZIP_VERSION : UNZIP_BZ2VERS);
  799. # define UNZVERS_SUPPORT unzvers_support
  800. #else
  801. # define UNZVERS_SUPPORT UNZIP_VERSION
  802. #endif
  803. /*---------------------------------------------------------------------------
  804. Check central directory info for version/compatibility requirements.
  805. ---------------------------------------------------------------------------*/
  806. G.pInfo->encrypted = G.crec.general_purpose_bit_flag & 1; /* bit field */
  807. G.pInfo->ExtLocHdr = (G.crec.general_purpose_bit_flag & 8) == 8; /* bit */
  808. G.pInfo->textfile = G.crec.internal_file_attributes & 1; /* bit field */
  809. G.pInfo->crc = G.crec.crc32;
  810. G.pInfo->compr_size = G.crec.csize;
  811. G.pInfo->uncompr_size = G.crec.ucsize;
  812. switch (uO.aflag) {
  813. case 0:
  814. G.pInfo->textmode = FALSE; /* bit field */
  815. break;
  816. case 1:
  817. G.pInfo->textmode = G.pInfo->textfile; /* auto-convert mode */
  818. break;
  819. default: /* case 2: */
  820. G.pInfo->textmode = TRUE;
  821. break;
  822. }
  823. if (G.crec.version_needed_to_extract[1] == VMS_) {
  824. if (G.crec.version_needed_to_extract[0] > VMS_UNZIP_VERSION) {
  825. if (!((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2)))
  826. Info(slide, 0x401, ((char *)slide, LoadFarString(VersionMsg),
  827. FnFilter1(G.filename), "VMS",
  828. G.crec.version_needed_to_extract[0] / 10,
  829. G.crec.version_needed_to_extract[0] % 10,
  830. VMS_UNZIP_VERSION / 10, VMS_UNZIP_VERSION % 10));
  831. return 0;
  832. }
  833. #ifndef VMS /* won't be able to use extra field, but still have data */
  834. else if (!uO.tflag && !IS_OVERWRT_ALL) { /* if -o, extract anyway */
  835. Info(slide, 0x481, ((char *)slide, LoadFarString(VMSFormatQuery),
  836. FnFilter1(G.filename)));
  837. fgets(G.answerbuf, sizeof(G.answerbuf), stdin);
  838. if ((*G.answerbuf != 'y') && (*G.answerbuf != 'Y'))
  839. return 0;
  840. }
  841. #endif /* !VMS */
  842. /* usual file type: don't need VMS to extract */
  843. } else if (G.crec.version_needed_to_extract[0] > UNZVERS_SUPPORT) {
  844. if (!((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2)))
  845. Info(slide, 0x401, ((char *)slide, LoadFarString(VersionMsg),
  846. FnFilter1(G.filename), "PK",
  847. G.crec.version_needed_to_extract[0] / 10,
  848. G.crec.version_needed_to_extract[0] % 10,
  849. UNZVERS_SUPPORT / 10, UNZVERS_SUPPORT % 10));
  850. return 0;
  851. }
  852. if (UNKN_COMPR) {
  853. if (!((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2))) {
  854. #ifndef SFX
  855. unsigned cmpridx;
  856. if ((cmpridx = find_compr_idx(G.crec.compression_method))
  857. < NUM_METHODS)
  858. Info(slide, 0x401, ((char *)slide, LoadFarString(ComprMsgName),
  859. FnFilter1(G.filename),
  860. LoadFarStringSmall(ComprNames[cmpridx])));
  861. else
  862. #endif
  863. Info(slide, 0x401, ((char *)slide, LoadFarString(ComprMsgNum),
  864. FnFilter1(G.filename),
  865. G.crec.compression_method));
  866. }
  867. return 0;
  868. }
  869. #if (!CRYPT)
  870. if (G.pInfo->encrypted) {
  871. if (!((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2)))
  872. Info(slide, 0x401, ((char *)slide, LoadFarString(SkipEncrypted),
  873. FnFilter1(G.filename)));
  874. return 0;
  875. }
  876. #endif /* !CRYPT */
  877. #ifndef SFX
  878. /* store a copy of the central header filename for later comparison */
  879. if ((G.pInfo->cfilname = zfmalloc(strlen(G.filename) + 1)) == NULL) {
  880. Info(slide, 0x401, ((char *)slide, LoadFarString(WarnNoMemCFName),
  881. FnFilter1(G.filename)));
  882. } else
  883. zfstrcpy(G.pInfo->cfilname, G.filename);
  884. #endif /* !SFX */
  885. /* map whatever file attributes we have into the local format */
  886. mapattr(__G); /* GRR: worry about return value later */
  887. G.pInfo->diskstart = G.crec.disk_number_start;
  888. G.pInfo->offset = (zoff_t)G.crec.relative_offset_local_header;
  889. return 1;
  890. } /* end function store_info() */
  891. #ifndef SFX
  892. /*******************************/
  893. /* Function find_compr_idx() */
  894. /*******************************/
  895. unsigned find_compr_idx(compr_methodnum)
  896. unsigned compr_methodnum;
  897. {
  898. unsigned i;
  899. for (i = 0; i < NUM_METHODS; i++) {
  900. if (ComprIDs[i] == compr_methodnum) break;
  901. }
  902. return i;
  903. }
  904. #endif /* !SFX */
  905. /******************************************/
  906. /* Function extract_or_test_entrylist() */
  907. /******************************************/
  908. static int extract_or_test_entrylist(__G__ numchunk,
  909. pfilnum, pnum_bad_pwd, pold_extra_bytes,
  910. #ifdef SET_DIR_ATTRIB
  911. pnum_dirs, pdirlist,
  912. #endif
  913. error_in_archive) /* return PK-type error code */
  914. __GDEF
  915. unsigned numchunk;
  916. ulg *pfilnum;
  917. ulg *pnum_bad_pwd;
  918. zoff_t *pold_extra_bytes;
  919. #ifdef SET_DIR_ATTRIB
  920. unsigned *pnum_dirs;
  921. direntry **pdirlist;
  922. #endif
  923. int error_in_archive;
  924. {
  925. unsigned i;
  926. int renamed, query;
  927. int skip_entry;
  928. zoff_t bufstart, inbuf_offset, request;
  929. int error, errcode;
  930. /* possible values for local skip_entry flag: */
  931. #define SKIP_NO 0 /* do not skip this entry */
  932. #define SKIP_Y_EXISTING 1 /* skip this entry, do not overwrite file */
  933. #define SKIP_Y_NONEXIST 2 /* skip this entry, do not create new file */
  934. /*-----------------------------------------------------------------------
  935. Second loop: process files in current block, extracting or testing
  936. each one.
  937. -----------------------------------------------------------------------*/
  938. for (i = 0; i < numchunk; ++i) {
  939. (*pfilnum)++; /* *pfilnum = i + blknum*DIR_BLKSIZ + 1; */
  940. G.pInfo = &G.info[i];
  941. #ifdef NOVELL_BUG_FAILSAFE
  942. G.dne = FALSE; /* assume file exists until stat() says otherwise */
  943. #endif
  944. /* if the target position is not within the current input buffer
  945. * (either haven't yet read far enough, or (maybe) skipping back-
  946. * ward), skip to the target position and reset readbuf(). */
  947. /* seek_zipf(__G__ pInfo->offset); */
  948. request = G.pInfo->offset + G.extra_bytes;
  949. inbuf_offset = request % INBUFSIZ;
  950. bufstart = request - inbuf_offset;
  951. Trace((stderr, "\ndebug: request = %ld, inbuf_offset = %ld\n",
  952. (long)request, (long)inbuf_offset));
  953. Trace((stderr,
  954. "debug: bufstart = %ld, cur_zipfile_bufstart = %ld\n",
  955. (long)bufstart, (long)G.cur_zipfile_bufstart));
  956. if (request < 0) {
  957. Info(slide, 0x401, ((char *)slide, LoadFarStringSmall(SeekMsg),
  958. G.zipfn, LoadFarString(ReportMsg)));
  959. error_in_archive = PK_ERR;
  960. if (*pfilnum == 1 && G.extra_bytes != 0L) {
  961. Info(slide, 0x401, ((char *)slide,
  962. LoadFarString(AttemptRecompensate)));
  963. *pold_extra_bytes = G.extra_bytes;
  964. G.extra_bytes = 0L;
  965. request = G.pInfo->offset; /* could also check if != 0 */
  966. inbuf_offset = request % INBUFSIZ;
  967. bufstart = request - inbuf_offset;
  968. Trace((stderr, "debug: request = %ld, inbuf_offset = %ld\n",
  969. (long)request, (long)inbuf_offset));
  970. Trace((stderr,
  971. "debug: bufstart = %ld, cur_zipfile_bufstart = %ld\n",
  972. (long)bufstart, (long)G.cur_zipfile_bufstart));
  973. /* try again */
  974. if (request < 0) {
  975. Trace((stderr,
  976. "debug: recompensated request still < 0\n"));
  977. Info(slide, 0x401, ((char *)slide,
  978. LoadFarStringSmall(SeekMsg),
  979. G.zipfn, LoadFarString(ReportMsg)));
  980. error_in_archive = PK_BADERR;
  981. continue;
  982. }
  983. } else {
  984. error_in_archive = PK_BADERR;
  985. continue; /* this one hosed; try next */
  986. }
  987. }
  988. if (bufstart != G.cur_zipfile_bufstart) {
  989. Trace((stderr, "debug: bufstart != cur_zipfile_bufstart\n"));
  990. #ifdef USE_STRM_INPUT
  991. zfseeko(G.zipfd, bufstart, SEEK_SET);
  992. G.cur_zipfile_bufstart = zftello(G.zipfd);
  993. #else /* !USE_STRM_INPUT */
  994. G.cur_zipfile_bufstart =
  995. zlseek(G.zipfd, bufstart, SEEK_SET);
  996. #endif /* ?USE_STRM_INPUT */
  997. if ((G.incnt = read(G.zipfd, (char *)G.inbuf, INBUFSIZ)) <= 0)
  998. {
  999. Info(slide, 0x401, ((char *)slide, LoadFarString(OffsetMsg),
  1000. *pfilnum, "lseek", (long)bufstart));
  1001. error_in_archive = PK_BADERR;
  1002. continue; /* can still do next file */
  1003. }
  1004. G.inptr = G.inbuf + (int)inbuf_offset;
  1005. G.incnt -= (int)inbuf_offset;
  1006. } else {
  1007. G.incnt += (int)(G.inptr-G.inbuf) - (int)inbuf_offset;
  1008. G.inptr = G.inbuf + (int)inbuf_offset;
  1009. }
  1010. /* should be in proper position now, so check for sig */
  1011. if (readbuf(__G__ G.sig, 4) == 0) { /* bad offset */
  1012. Info(slide, 0x401, ((char *)slide, LoadFarString(OffsetMsg),
  1013. *pfilnum, "EOF", (long)request));
  1014. error_in_archive = PK_BADERR;
  1015. continue; /* but can still try next one */
  1016. }
  1017. if (memcmp(G.sig, local_hdr_sig, 4)) {
  1018. Info(slide, 0x401, ((char *)slide, LoadFarString(OffsetMsg),
  1019. *pfilnum, LoadFarStringSmall(LocalHdrSig), (long)request));
  1020. /*
  1021. GRRDUMP(G.sig, 4)
  1022. GRRDUMP(local_hdr_sig, 4)
  1023. */
  1024. error_in_archive = PK_ERR;
  1025. if ((*pfilnum == 1 && G.extra_bytes != 0L) ||
  1026. (G.extra_bytes == 0L && *pold_extra_bytes != 0L)) {
  1027. Info(slide, 0x401, ((char *)slide,
  1028. LoadFarString(AttemptRecompensate)));
  1029. if (G.extra_bytes) {
  1030. *pold_extra_bytes = G.extra_bytes;
  1031. G.extra_bytes = 0L;
  1032. } else
  1033. G.extra_bytes = *pold_extra_bytes; /* third attempt */
  1034. if (((error = seek_zipf(__G__ G.pInfo->offset)) != PK_OK) ||
  1035. (readbuf(__G__ G.sig, 4) == 0)) { /* bad offset */
  1036. if (error != PK_BADERR)
  1037. Info(slide, 0x401, ((char *)slide,
  1038. LoadFarString(OffsetMsg), *pfilnum, "EOF",
  1039. (long)request));
  1040. error_in_archive = PK_BADERR;
  1041. continue; /* but can still try next one */
  1042. }
  1043. if (memcmp(G.sig, local_hdr_sig, 4)) {
  1044. Info(slide, 0x401, ((char *)slide,
  1045. LoadFarString(OffsetMsg), *pfilnum,
  1046. LoadFarStringSmall(LocalHdrSig), (long)request));
  1047. error_in_archive = PK_BADERR;
  1048. continue;
  1049. }
  1050. } else
  1051. continue; /* this one hosed; try next */
  1052. }
  1053. if ((error = process_local_file_hdr(__G)) != PK_COOL) {
  1054. Info(slide, 0x421, ((char *)slide, LoadFarString(BadLocalHdr),
  1055. *pfilnum));
  1056. error_in_archive = error; /* only PK_EOF defined */
  1057. continue; /* can still try next one */
  1058. }
  1059. #if (!defined(SFX) && defined(UNICODE_SUPPORT))
  1060. if (((G.lrec.general_purpose_bit_flag & (1 << 11)) == (1 << 11))
  1061. != (G.pInfo->GPFIsUTF8 != 0)) {
  1062. if (QCOND2) {
  1063. # ifdef SMALL_MEM
  1064. char *temp_cfilnam = slide + (7 * (WSIZE>>3));
  1065. zfstrcpy((char Far *)temp_cfilnam, G.pInfo->cfilname);
  1066. # define cFile_PrintBuf temp_cfilnam
  1067. # else
  1068. # define cFile_PrintBuf G.pInfo->cfilname
  1069. # endif
  1070. Info(slide, 0x421, ((char *)slide,
  1071. LoadFarStringSmall2(GP11FlagsDiffer),
  1072. *pfilnum, FnFilter1(cFile_PrintBuf), G.pInfo->GPFIsUTF8));
  1073. # undef cFile_PrintBuf
  1074. }
  1075. if (error_in_archive < PK_WARN)
  1076. error_in_archive = PK_WARN;
  1077. }
  1078. #endif /* !SFX && UNICODE_SUPPORT */
  1079. if ((error = do_string(__G__ G.lrec.filename_length, DS_FN_L)) !=
  1080. PK_COOL)
  1081. {
  1082. if (error > error_in_archive)
  1083. error_in_archive = error;
  1084. if (error > PK_WARN) {
  1085. Info(slide, 0x401, ((char *)slide, LoadFarString(FilNamMsg),
  1086. FnFilter1(G.filename), "local"));
  1087. continue; /* go on to next one */
  1088. }
  1089. }
  1090. if (G.extra_field != (uch *)NULL) {
  1091. free(G.extra_field);
  1092. G.extra_field = (uch *)NULL;
  1093. }
  1094. if ((error =
  1095. do_string(__G__ G.lrec.extra_field_length, EXTRA_FIELD)) != 0)
  1096. {
  1097. if (error > error_in_archive)
  1098. error_in_archive = error;
  1099. if (error > PK_WARN) {
  1100. Info(slide, 0x401, ((char *)slide,
  1101. LoadFarString(ExtFieldMsg),
  1102. FnFilter1(G.filename), "local"));
  1103. continue; /* go on */
  1104. }
  1105. }
  1106. #ifndef SFX
  1107. /* Filename consistency checks must come after reading in the local
  1108. * extra field, so that a UTF-8 entry name e.f. block has already
  1109. * been processed.
  1110. */
  1111. if (G.pInfo->cfilname != (char Far *)NULL) {
  1112. if (zfstrcmp(G.pInfo->cfilname, G.filename) != 0) {
  1113. # ifdef SMALL_MEM
  1114. char *temp_cfilnam = slide + (7 * (WSIZE>>3));
  1115. zfstrcpy((char Far *)temp_cfilnam, G.pInfo->cfilname);
  1116. # define cFile_PrintBuf temp_cfilnam
  1117. # else
  1118. # define cFile_PrintBuf G.pInfo->cfilname
  1119. # endif
  1120. Info(slide, 0x401, ((char *)slide,
  1121. LoadFarStringSmall2(LvsCFNamMsg),
  1122. FnFilter2(cFile_PrintBuf), FnFilter1(G.filename)));
  1123. # undef cFile_PrintBuf
  1124. zfstrcpy(G.filename, G.pInfo->cfilname);
  1125. if (error_in_archive < PK_WARN)
  1126. error_in_archive = PK_WARN;
  1127. }
  1128. zffree(G.pInfo->cfilname);
  1129. G.pInfo->cfilname = (char Far *)NULL;
  1130. }
  1131. #endif /* !SFX */
  1132. /* Size consistency checks must come after reading in the local extra
  1133. * field, so that any Zip64 extension local e.f. block has already
  1134. * been processed.
  1135. */
  1136. if (G.lrec.compression_method == STORED) {
  1137. zusz_t csiz_decrypted = G.lrec.csize;
  1138. if (G.pInfo->encrypted)
  1139. csiz_decrypted -= 12;
  1140. if (G.lrec.ucsize != csiz_decrypted) {
  1141. Info(slide, 0x401, ((char *)slide,
  1142. LoadFarStringSmall2(WrnStorUCSizCSizDiff),
  1143. FnFilter1(G.filename),
  1144. FmZofft(G.lrec.ucsize, NULL, "u"),
  1145. FmZofft(csiz_decrypted, NULL, "u")));
  1146. G.lrec.ucsize = csiz_decrypted;
  1147. if (error_in_archive < PK_WARN)
  1148. error_in_archive = PK_WARN;
  1149. }
  1150. }
  1151. #if CRYPT
  1152. if (G.pInfo->encrypted &&
  1153. (error = decrypt(__G__ uO.pwdarg)) != PK_COOL) {
  1154. if (error == PK_WARN) {
  1155. if (!((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2)))
  1156. Info(slide, 0x401, ((char *)slide,
  1157. LoadFarString(SkipIncorrectPasswd),
  1158. FnFilter1(G.filename)));
  1159. ++(*pnum_bad_pwd);
  1160. } else { /* (error > PK_WARN) */
  1161. if (error > error_in_archive)
  1162. error_in_archive = error;
  1163. Info(slide, 0x401, ((char *)slide,
  1164. LoadFarString(SkipCannotGetPasswd),
  1165. FnFilter1(G.filename)));
  1166. }
  1167. continue; /* go on to next file */
  1168. }
  1169. #endif /* CRYPT */
  1170. /*
  1171. * just about to extract file: if extracting to disk, check if
  1172. * already exists, and if so, take appropriate action according to
  1173. * fflag/uflag/overwrite_all/etc. (we couldn't do this in upper
  1174. * loop because we don't store the possibly renamed filename[] in
  1175. * info[])
  1176. */
  1177. #ifdef DLL
  1178. if (!uO.tflag && !uO.cflag && !G.redirect_data)
  1179. #else
  1180. if (!uO.tflag && !uO.cflag)
  1181. #endif
  1182. {
  1183. renamed = FALSE; /* user hasn't renamed output file yet */
  1184. startover:
  1185. query = FALSE;
  1186. skip_entry = SKIP_NO;
  1187. /* for files from DOS FAT, check for use of backslash instead
  1188. * of slash as directory separator (bug in some zipper(s); so
  1189. * far, not a problem in HPFS, NTFS or VFAT systems)
  1190. */
  1191. #ifndef SFX
  1192. if (G.pInfo->hostnum == FS_FAT_ && !MBSCHR(G.filename, '/')) {
  1193. char *p=G.filename;
  1194. if (*p) do {
  1195. if (*p == '\\') {
  1196. if (!G.reported_backslash) {
  1197. Info(slide, 0x21, ((char *)slide,
  1198. LoadFarString(BackslashPathSep), G.zipfn));
  1199. G.reported_backslash = TRUE;
  1200. if (!error_in_archive)
  1201. error_in_archive = PK_WARN;
  1202. }
  1203. *p = '/';
  1204. }
  1205. } while (*PREINCSTR(p));
  1206. }
  1207. #endif /* !SFX */
  1208. if (!renamed) {
  1209. /* remove absolute path specs */
  1210. if (G.filename[0] == '/') {
  1211. Info(slide, 0x401, ((char *)slide,
  1212. LoadFarString(AbsolutePathWarning),
  1213. FnFilter1(G.filename)));
  1214. if (!error_in_archive)
  1215. error_in_archive = PK_WARN;
  1216. do {
  1217. char *p = G.filename + 1;
  1218. do {
  1219. *(p-1) = *p;
  1220. } while (*p++ != '\0');
  1221. } while (G.filename[0] == '/');
  1222. }
  1223. }
  1224. /* mapname can create dirs if not freshening or if renamed */
  1225. error = mapname(__G__ renamed);
  1226. if ((errcode = error & ~MPN_MASK) != PK_OK &&
  1227. error_in_archive < errcode)
  1228. error_in_archive = errcode;
  1229. if ((errcode = error & MPN_MASK) > MPN_INF_TRUNC) {
  1230. if (errcode == MPN_CREATED_DIR) {
  1231. #ifdef SET_DIR_ATTRIB
  1232. direntry *d_entry;
  1233. error = defer_dir_attribs(__G__ &d_entry);
  1234. if (d_entry == (direntry *)NULL) {
  1235. /* There may be no dir_attribs info available, or
  1236. * we have encountered a mem allocation error.
  1237. * In case of an error, report it and set program
  1238. * error state to warning level.
  1239. */
  1240. if (error) {
  1241. Info(slide, 0x401, ((char *)slide,
  1242. LoadFarString(DirlistEntryNoMem)));
  1243. if (!error_in_archive)
  1244. error_in_archive = PK_WARN;
  1245. }
  1246. } else {
  1247. d_entry->next = (*pdirlist);
  1248. (*pdirlist) = d_entry;
  1249. ++(*pnum_dirs);
  1250. }
  1251. #endif /* SET_DIR_ATTRIB */
  1252. } else if (errcode == MPN_VOL_LABEL) {
  1253. #ifdef DOS_OS2_W32
  1254. Info(slide, 0x401, ((char *)slide,
  1255. LoadFarString(SkipVolumeLabel),
  1256. FnFilter1(G.filename),
  1257. uO.volflag? "hard disk " : ""));
  1258. #else
  1259. Info(slide, 1, ((char *)slide,
  1260. LoadFarString(SkipVolumeLabel),
  1261. FnFilter1(G.filename), ""));
  1262. #endif
  1263. } else if (errcode > MPN_INF_SKIP &&
  1264. error_in_archive < PK_ERR)
  1265. error_in_archive = PK_ERR;
  1266. Trace((stderr, "mapname(%s) returns error code = %d\n",
  1267. FnFilter1(G.filename), error));
  1268. continue; /* go on to next file */
  1269. }
  1270. #ifdef QDOS
  1271. QFilename(__G__ G.filename);
  1272. #endif
  1273. switch (check_for_newer(__G__ G.filename)) {
  1274. case DOES_NOT_EXIST:
  1275. #ifdef NOVELL_BUG_FAILSAFE
  1276. G.dne = TRUE; /* stat() says file DOES NOT EXIST */
  1277. #endif
  1278. /* freshen (no new files): skip unless just renamed */
  1279. if (uO.fflag && !renamed)
  1280. skip_entry = SKIP_Y_NONEXIST;
  1281. break;
  1282. case EXISTS_AND_OLDER:
  1283. #ifdef UNIXBACKUP
  1284. if (!uO.B_flag)
  1285. #endif
  1286. {
  1287. if (IS_OVERWRT_NONE)
  1288. /* never overwrite: skip file */
  1289. skip_entry = SKIP_Y_EXISTING;
  1290. else if (!IS_OVERWRT_ALL)
  1291. query = TRUE;
  1292. }
  1293. break;
  1294. case EXISTS_AND_NEWER: /* (or equal) */
  1295. #ifdef UNIXBACKUP
  1296. if ((!uO.B_flag && IS_OVERWRT_NONE) ||
  1297. #else
  1298. if (IS_OVERWRT_NONE ||
  1299. #endif
  1300. (uO.uflag && !renamed)) {
  1301. /* skip if update/freshen & orig name */
  1302. skip_entry = SKIP_Y_EXISTING;
  1303. } else {
  1304. #ifdef UNIXBACKUP
  1305. if (!IS_OVERWRT_ALL && !uO.B_flag)
  1306. #else
  1307. if (!IS_OVERWRT_ALL)
  1308. #endif
  1309. query = TRUE;
  1310. }
  1311. break;
  1312. }
  1313. #ifdef VMS
  1314. /* 2008-07-24 SMS.
  1315. * On VMS, if the file name includes a version number,
  1316. * and "-V" ("retain VMS version numbers", V_flag) is in
  1317. * effect, then the VMS-specific code will handle any
  1318. * conflicts with an existing file, making this query
  1319. * redundant. (Implicit "y" response here.)
  1320. */
  1321. if (query && uO.V_flag) {
  1322. /* Not discarding file versions. Look for one. */
  1323. int cndx = strlen(G.filename) - 1;
  1324. while ((cndx > 0) && (isdigit(G.filename[cndx])))
  1325. cndx--;
  1326. if (G.filename[cndx] == ';')
  1327. /* File version found; skip the generic query,
  1328. * proceeding with its default response "y".
  1329. */
  1330. query = FALSE;
  1331. }
  1332. #endif /* VMS */
  1333. if (query) {
  1334. #ifdef WINDLL
  1335. switch (G.lpUserFunctions->replace != NULL ?
  1336. (*G.lpUserFunctions->replace)(G.filename, FILNAMSIZ) :
  1337. IDM_REPLACE_NONE) {
  1338. case IDM_REPLACE_RENAME:
  1339. _ISO_INTERN(G.filename);
  1340. renamed = TRUE;
  1341. goto startover;
  1342. case IDM_REPLACE_ALL:
  1343. G.overwrite_mode = OVERWRT_ALWAYS;
  1344. /* FALL THROUGH, extract */
  1345. case IDM_REPLACE_YES:
  1346. break;
  1347. case IDM_REPLACE_NONE:
  1348. G.overwrite_mode = OVERWRT_NEVER;
  1349. /* FALL THROUGH, skip */
  1350. case IDM_REPLACE_NO:
  1351. skip_entry = SKIP_Y_EXISTING;
  1352. break;
  1353. }
  1354. #else /* !WINDLL */
  1355. extent fnlen;
  1356. reprompt:
  1357. Info(slide, 0x81, ((char *)slide,
  1358. LoadFarString(ReplaceQuery),
  1359. FnFilter1(G.filename)));
  1360. if (fgets(G.answerbuf, sizeof(G.answerbuf), stdin)
  1361. == (char *)NULL) {
  1362. Info(slide, 1, ((char *)slide,
  1363. LoadFarString(AssumeNone)));
  1364. *G.answerbuf = 'N';
  1365. if (!error_in_archive)
  1366. error_in_archive = 1; /* not extracted: warning */
  1367. }
  1368. switch (*G.answerbuf) {
  1369. case 'r':
  1370. case 'R':
  1371. do {
  1372. Info(slide, 0x81, ((char *)slide,
  1373. LoadFarString(NewNameQuery)));
  1374. fgets(G.filename, FILNAMSIZ, stdin);
  1375. /* usually get \n here: better check for it */
  1376. fnlen = strlen(G.filename);
  1377. if (lastchar(G.filename, fnlen) == '\n')
  1378. G.filename[--fnlen] = '\0';
  1379. } while (fnlen == 0);
  1380. #ifdef WIN32 /* WIN32 fgets( ... , stdin) returns OEM coded strings */
  1381. _OEM_INTERN(G.filename);
  1382. #endif
  1383. renamed = TRUE;
  1384. goto startover; /* sorry for a goto */
  1385. case 'A': /* dangerous option: force caps */
  1386. G.overwrite_mode = OVERWRT_ALWAYS;
  1387. /* FALL THROUGH, extract */
  1388. case 'y':
  1389. case 'Y':
  1390. break;
  1391. case 'N':
  1392. G.overwrite_mode = OVERWRT_NEVER;
  1393. /* FALL THROUGH, skip */
  1394. case 'n':
  1395. /* skip file */
  1396. skip_entry = SKIP_Y_EXISTING;
  1397. break;
  1398. case '\n':
  1399. case '\r':
  1400. /* Improve echo of '\n' and/or '\r'
  1401. (sizeof(G.answerbuf) == 10 (see globals.h), so
  1402. there is enough space for the provided text...) */
  1403. strcpy(G.answerbuf, "{ENTER}");
  1404. /* fall through ... */
  1405. default:
  1406. /* usually get \n here: remove it for nice display
  1407. (fnlen can be re-used here, we are outside the
  1408. "enter new filename" loop) */
  1409. fnlen = strlen(G.answerbuf);
  1410. if (lastchar(G.answerbuf, fnlen) == '\n')
  1411. G.answerbuf[--fnlen] = '\0';
  1412. Info(slide, 1, ((char *)slide,
  1413. LoadFarString(InvalidResponse), G.answerbuf));
  1414. goto reprompt; /* yet another goto? */
  1415. } /* end switch (*answerbuf) */
  1416. #endif /* ?WINDLL */
  1417. } /* end if (query) */
  1418. if (skip_entry != SKIP_NO) {
  1419. #ifdef WINDLL
  1420. if (skip_entry == SKIP_Y_EXISTING) {
  1421. /* report skipping of an existing entry */
  1422. Info(slide, 0, ((char *)slide,
  1423. ((IS_OVERWRT_NONE || !uO.uflag || renamed) ?
  1424. "Target file exists. Skipping %s\n" :
  1425. "Target file newer. Skipping %s\n"),
  1426. FnFilter1(G.filename)));
  1427. }
  1428. #endif /* WINDLL */
  1429. continue;
  1430. }
  1431. } /* end if (extracting to disk) */
  1432. #ifdef DLL
  1433. if ((G.statreportcb != NULL) &&
  1434. (*G.statreportcb)(__G__ UZ_ST_START_EXTRACT, G.zipfn,
  1435. G.filename, NULL)) {
  1436. return IZ_CTRLC; /* cancel operation by user request */
  1437. }
  1438. #endif
  1439. #ifdef MACOS /* MacOS is no preemptive OS, thus call event-handling by hand */
  1440. UserStop();
  1441. #endif
  1442. #ifdef AMIGA
  1443. G.filenote_slot = i;
  1444. #endif
  1445. G.disk_full = 0;
  1446. if ((error = extract_or_test_member(__G)) != PK_COOL) {
  1447. if (error > error_in_archive)
  1448. error_in_archive = error; /* ...and keep going */
  1449. #ifdef DLL
  1450. if (G.disk_full > 1 || error_in_archive == IZ_CTRLC) {
  1451. #else
  1452. if (G.disk_full > 1) {
  1453. #endif
  1454. return error_in_archive; /* (unless disk full) */
  1455. }
  1456. }
  1457. #ifdef DLL
  1458. if ((G.statreportcb != NULL) &&
  1459. (*G.statreportcb)(__G__ UZ_ST_FINISH_MEMBER, G.zipfn,
  1460. G.filename, (zvoid *)&G.lrec.ucsize)) {
  1461. return IZ_CTRLC; /* cancel operation by user request */
  1462. }
  1463. #endif
  1464. #ifdef MACOS /* MacOS is no preemptive OS, thus call event-handling by hand */
  1465. UserStop();
  1466. #endif
  1467. } /* end for-loop (i: files in current block) */
  1468. return error_in_archive;
  1469. } /* end function extract_or_test_entrylist() */
  1470. /* wsize is used in extract_or_test_member() and UZbunzip2() */
  1471. #if (defined(DLL) && !defined(NO_SLIDE_REDIR))
  1472. # define wsize G._wsize /* wsize is a variable */
  1473. #else
  1474. # define wsize WSIZE /* wsize is a constant */
  1475. #endif
  1476. /***************************************/
  1477. /* Function extract_or_test_member() */
  1478. /***************************************/
  1479. static int extract_or_test_member(__G) /* return PK-type error code */
  1480. __GDEF
  1481. {
  1482. char *nul="[empty] ", *txt="[text] ", *bin="[binary]";
  1483. #ifdef CMS_MVS
  1484. char *ebc="[ebcdic]";
  1485. #endif
  1486. register int b;
  1487. int r, error=PK_COOL;
  1488. /*---------------------------------------------------------------------------
  1489. Initialize variables, buffers, etc.
  1490. ---------------------------------------------------------------------------*/
  1491. G.bits_left = 0;
  1492. G.bitbuf = 0L; /* unreduce and unshrink only */
  1493. G.zipeof = 0;
  1494. G.newfile = TRUE;
  1495. G.crc32val = CRCVAL_INITIAL;
  1496. #ifdef SYMLINKS
  1497. /* If file is a (POSIX-compatible) symbolic link and we are extracting
  1498. * to disk, prepare to restore the link. */
  1499. G.symlnk = (G.pInfo->symlink &&
  1500. !uO.tflag && !uO.cflag && (G.lrec.ucsize > 0));
  1501. #endif /* SYMLINKS */
  1502. if (uO.tflag) {
  1503. if (!uO.qflag)
  1504. Info(slide, 0, ((char *)slide, LoadFarString(ExtractMsg), "test",
  1505. FnFilter1(G.filename), "", ""));
  1506. } else {
  1507. #ifdef DLL
  1508. if (uO.cflag && !G.redirect_data)
  1509. #else
  1510. if (uO.cflag)
  1511. #endif
  1512. {
  1513. #if (defined(OS2) && defined(__IBMC__) && (__IBMC__ >= 200))
  1514. G.outfile = freopen("", "wb", stdout); /* VAC++ ignores setmode */
  1515. #else
  1516. G.outfile = stdout;
  1517. #endif
  1518. #ifdef DOS_FLX_NLM_OS2_W32
  1519. #if (defined(__HIGHC__) && !defined(FLEXOS))
  1520. setmode(G.outfile, _BINARY);
  1521. #else /* !(defined(__HIGHC__) && !defined(FLEXOS)) */
  1522. setmode(fileno(G.outfile), O_BINARY);
  1523. #endif /* ?(defined(__HIGHC__) && !defined(FLEXOS)) */
  1524. # define NEWLINE "\r\n"
  1525. #else /* !DOS_FLX_NLM_OS2_W32 */
  1526. # define NEWLINE "\n"
  1527. #endif /* ?DOS_FLX_NLM_OS2_W32 */
  1528. #ifdef VMS
  1529. /* VMS: required even for stdout! */
  1530. if ((r = open_outfile(__G)) != 0)
  1531. switch (r) {
  1532. case OPENOUT_SKIPOK:
  1533. return PK_OK;
  1534. case OPENOUT_SKIPWARN:
  1535. return PK_WARN;
  1536. default:
  1537. return PK_DISK;
  1538. }
  1539. } else if ((r = open_outfile(__G)) != 0)
  1540. switch (r) {
  1541. case OPENOUT_SKIPOK:
  1542. return PK_OK;
  1543. case OPENOUT_SKIPWARN:
  1544. return PK_WARN;
  1545. default:
  1546. return PK_DISK;
  1547. }
  1548. #else /* !VMS */
  1549. } else if (open_outfile(__G))
  1550. return PK_DISK;
  1551. #endif /* ?VMS */
  1552. }
  1553. /*---------------------------------------------------------------------------
  1554. Unpack the file.
  1555. ---------------------------------------------------------------------------*/
  1556. defer_leftover_input(__G); /* so NEXTBYTE bounds check will work */
  1557. switch (G.lrec.compression_method) {
  1558. case STORED:
  1559. if (!uO.tflag && QCOND2) {
  1560. #ifdef SYMLINKS
  1561. if (G.symlnk) /* can also be deflated, but rarer... */
  1562. Info(slide, 0, ((char *)slide, LoadFarString(ExtractMsg),
  1563. "link", FnFilter1(G.filename), "", ""));
  1564. else
  1565. #endif /* SYMLINKS */
  1566. Info(slide, 0, ((char *)slide, LoadFarString(ExtractMsg),
  1567. "extract", FnFilter1(G.filename),
  1568. (uO.aflag != 1 /* && G.pInfo->textfile==G.pInfo->textmode */)?
  1569. "" : (G.lrec.ucsize == 0L? nul : (G.pInfo->textfile? txt :
  1570. bin)), uO.cflag? NEWLINE : ""));
  1571. }
  1572. #if (defined(DLL) && !defined(NO_SLIDE_REDIR))
  1573. if (G.redirect_slide) {
  1574. wsize = G.redirect_size; redirSlide = G.redirect_buffer;
  1575. } else {
  1576. wsize = WSIZE; redirSlide = slide;
  1577. }
  1578. #endif
  1579. G.outptr = redirSlide;
  1580. G.outcnt = 0L;
  1581. while ((b = NEXTBYTE) != EOF) {
  1582. *G.outptr++ = (uch)b;
  1583. if (++G.outcnt == wsize) {
  1584. error = flush(__G__ redirSlide, G.outcnt, 0);
  1585. G.outptr = redirSlide;
  1586. G.outcnt = 0L;
  1587. if (error != PK_COOL || G.disk_full) break;
  1588. }
  1589. }
  1590. if (G.outcnt) { /* flush final (partial) buffer */
  1591. r = flush(__G__ redirSlide, G.outcnt, 0);
  1592. if (error < r) error = r;
  1593. }
  1594. break;
  1595. #ifndef SFX
  1596. #ifndef LZW_CLEAN
  1597. case SHRUNK:
  1598. if (!uO.tflag && QCOND2) {
  1599. Info(slide, 0, ((char *)slide, LoadFarString(ExtractMsg),
  1600. LoadFarStringSmall(Unshrink), FnFilter1(G.filename),
  1601. (uO.aflag != 1 /* && G.pInfo->textfile==G.pInfo->textmode */)?
  1602. "" : (G.pInfo->textfile? txt : bin), uO.cflag? NEWLINE : ""));
  1603. }
  1604. if ((r = unshrink(__G)) != PK_COOL) {
  1605. if (r < PK_DISK) {
  1606. if ((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2))
  1607. Info(slide, 0x401, ((char *)slide,
  1608. LoadFarStringSmall(ErrUnzipFile), r == PK_MEM3 ?
  1609. LoadFarString(NotEnoughMem) :
  1610. LoadFarString(InvalidComprData),
  1611. LoadFarStringSmall2(Unshrink),
  1612. FnFilter1(G.filename)));
  1613. else
  1614. Info(slide, 0x401, ((char *)slide,
  1615. LoadFarStringSmall(ErrUnzipNoFile), r == PK_MEM3 ?
  1616. LoadFarString(NotEnoughMem) :
  1617. LoadFarString(InvalidComprData),
  1618. LoadFarStringSmall2(Unshrink)));
  1619. }
  1620. error = r;
  1621. }
  1622. break;
  1623. #endif /* !LZW_CLEAN */
  1624. #ifndef COPYRIGHT_CLEAN
  1625. case REDUCED1:
  1626. case REDUCED2:
  1627. case REDUCED3:
  1628. case REDUCED4:
  1629. if (!uO.tflag && QCOND2) {
  1630. Info(slide, 0, ((char *)slide, LoadFarString(ExtractMsg),
  1631. "unreduc", FnFilter1(G.filename),
  1632. (uO.aflag != 1 /* && G.pInfo->textfile==G.pInfo->textmode */)?
  1633. "" : (G.pInfo->textfile? txt : bin), uO.cflag? NEWLINE : ""));
  1634. }
  1635. if ((r = unreduce(__G)) != PK_COOL) {
  1636. /* unreduce() returns only PK_COOL, PK_DISK, or IZ_CTRLC */
  1637. error = r;
  1638. }
  1639. break;
  1640. #endif /* !COPYRIGHT_CLEAN */
  1641. case IMPLODED:
  1642. if (!uO.tflag && QCOND2) {
  1643. Info(slide, 0, ((char *)slide, LoadFarString(ExtractMsg),
  1644. "explod", FnFilter1(G.filename),
  1645. (uO.aflag != 1 /* && G.pInfo->textfile==G.pInfo->textmode */)?
  1646. "" : (G.pInfo->textfile? txt : bin), uO.cflag? NEWLINE : ""));
  1647. }
  1648. if ((r = explode(__G)) != 0) {
  1649. if (r == 5) { /* treat 5 specially */
  1650. int warning = ((zusz_t)G.used_csize <= G.lrec.csize);
  1651. if ((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2))
  1652. Info(slide, 0x401, ((char *)slide,
  1653. LoadFarString(LengthMsg),
  1654. "", warning ? "warning" : "error",
  1655. FmZofft(G.used_csize, NULL, NULL),
  1656. FmZofft(G.lrec.ucsize, NULL, "u"),
  1657. warning ? " " : "",
  1658. FmZofft(G.lrec.csize, NULL, "u"),
  1659. " [", FnFilter1(G.filename), "]"));
  1660. else
  1661. Info(slide, 0x401, ((char *)slide,
  1662. LoadFarString(LengthMsg),
  1663. "\n", warning ? "warning" : "error",
  1664. FmZofft(G.used_csize, NULL, NULL),
  1665. FmZofft(G.lrec.ucsize, NULL, "u"),
  1666. warning ? " " : "",
  1667. FmZofft(G.lrec.csize, NULL, "u"),
  1668. "", "", "."));
  1669. error = warning ? PK_WARN : PK_ERR;
  1670. } else if (r < PK_DISK) {
  1671. if ((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2))
  1672. Info(slide, 0x401, ((char *)slide,
  1673. LoadFarStringSmall(ErrUnzipFile), r == 3?
  1674. LoadFarString(NotEnoughMem) :
  1675. LoadFarString(InvalidComprData),
  1676. LoadFarStringSmall2(Explode),
  1677. FnFilter1(G.filename)));
  1678. else
  1679. Info(slide, 0x401, ((char *)slide,
  1680. LoadFarStringSmall(ErrUnzipNoFile), r == 3?
  1681. LoadFarString(NotEnoughMem) :
  1682. LoadFarString(InvalidComprData),
  1683. LoadFarStringSmall2(Explode)));
  1684. error = ((r == 3) ? PK_MEM3 : PK_ERR);
  1685. } else {
  1686. error = r;
  1687. }
  1688. }
  1689. break;
  1690. #endif /* !SFX */
  1691. case DEFLATED:
  1692. #ifdef USE_DEFLATE64
  1693. case ENHDEFLATED:
  1694. #endif
  1695. if (!uO.tflag && QCOND2) {
  1696. Info(slide, 0, ((char *)slide, LoadFarString(ExtractMsg),
  1697. "inflat", FnFilter1(G.filename),
  1698. (uO.aflag != 1 /* && G.pInfo->textfile==G.pInfo->textmode */)?
  1699. "" : (G.pInfo->textfile? txt : bin), uO.cflag? NEWLINE : ""));
  1700. }
  1701. #ifndef USE_ZLIB /* zlib's function is called inflate(), too */
  1702. # define UZinflate inflate
  1703. #endif
  1704. if ((r = UZinflate(__G__
  1705. (G.lrec.compression_method == ENHDEFLATED)))
  1706. != 0) {
  1707. if (r < PK_DISK) {
  1708. if ((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2))
  1709. Info(slide, 0x401, ((char *)slide,
  1710. LoadFarStringSmall(ErrUnzipFile), r == 3?
  1711. LoadFarString(NotEnoughMem) :
  1712. LoadFarString(InvalidComprData),
  1713. LoadFarStringSmall2(Inflate),
  1714. FnFilter1(G.filename)));
  1715. else
  1716. Info(slide, 0x401, ((char *)slide,
  1717. LoadFarStringSmall(ErrUnzipNoFile), r == 3?
  1718. LoadFarString(NotEnoughMem) :
  1719. LoadFarString(InvalidComprData),
  1720. LoadFarStringSmall2(Inflate)));
  1721. error = ((r == 3) ? PK_MEM3 : PK_ERR);
  1722. } else {
  1723. error = r;
  1724. }
  1725. }
  1726. break;
  1727. #ifdef USE_BZIP2
  1728. case BZIPPED:
  1729. if (!uO.tflag && QCOND2) {
  1730. Info(slide, 0, ((char *)slide, LoadFarString(ExtractMsg),
  1731. "bunzipp", FnFilter1(G.filename),
  1732. (uO.aflag != 1 /* && G.pInfo->textfile==G.pInfo->textmode */)?
  1733. "" : (G.pInfo->textfile? txt : bin), uO.cflag? NEWLINE : ""));
  1734. }
  1735. if ((r = UZbunzip2(__G)) != 0) {
  1736. if (r < PK_DISK) {
  1737. if ((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2))
  1738. Info(slide, 0x401, ((char *)slide,
  1739. LoadFarStringSmall(ErrUnzipFile), r == 3?
  1740. LoadFarString(NotEnoughMem) :
  1741. LoadFarString(InvalidComprData),
  1742. LoadFarStringSmall2(BUnzip),
  1743. FnFilter1(G.filename)));
  1744. else
  1745. Info(slide, 0x401, ((char *)slide,
  1746. LoadFarStringSmall(ErrUnzipNoFile), r == 3?
  1747. LoadFarString(NotEnoughMem) :
  1748. LoadFarString(InvalidComprData),
  1749. LoadFarStringSmall2(BUnzip)));
  1750. error = ((r == 3) ? PK_MEM3 : PK_ERR);
  1751. } else {
  1752. error = r;
  1753. }
  1754. }
  1755. break;
  1756. #endif /* USE_BZIP2 */
  1757. default: /* should never get to this point */
  1758. Info(slide, 0x401, ((char *)slide,
  1759. LoadFarString(FileUnknownCompMethod), FnFilter1(G.filename)));
  1760. /* close and delete file before return? */
  1761. undefer_input(__G);
  1762. return PK_WARN;
  1763. } /* end switch (compression method) */
  1764. /*---------------------------------------------------------------------------
  1765. Close the file and set its date and time (not necessarily in that order),
  1766. and make sure the CRC checked out OK. Logical-AND the CRC for 64-bit
  1767. machines (redundant on 32-bit machines).
  1768. ---------------------------------------------------------------------------*/
  1769. #ifdef VMS /* VMS: required even for stdout! (final flush) */
  1770. if (!uO.tflag) /* don't close NULL file */
  1771. close_outfile(__G);
  1772. #else
  1773. #ifdef DLL
  1774. if (!uO.tflag && (!uO.cflag || G.redirect_data)) {
  1775. if (G.redirect_data)
  1776. FINISH_REDIRECT();
  1777. else
  1778. close_outfile(__G);
  1779. }
  1780. #else
  1781. if (!uO.tflag && !uO.cflag) /* don't close NULL file or stdout */
  1782. close_outfile(__G);
  1783. #endif
  1784. #endif /* VMS */
  1785. /* GRR: CONVERT close_outfile() TO NON-VOID: CHECK FOR ERRORS! */
  1786. if (G.disk_full) { /* set by flush() */
  1787. if (G.disk_full > 1) {
  1788. #if (defined(DELETE_IF_FULL) && defined(HAVE_UNLINK))
  1789. /* delete the incomplete file if we can */
  1790. if (unlink(G.filename) != 0)
  1791. Trace((stderr, "extract.c: could not delete %s\n",
  1792. FnFilter1(G.filename)));
  1793. #else
  1794. /* warn user about the incomplete file */
  1795. Info(slide, 0x421, ((char *)slide, LoadFarString(FileTruncated),
  1796. FnFilter1(G.filename)));
  1797. #endif
  1798. error = PK_DISK;
  1799. } else {
  1800. error = PK_WARN;
  1801. }
  1802. }
  1803. if (error > PK_WARN) {/* don't print redundant CRC error if error already */
  1804. undefer_input(__G);
  1805. return error;
  1806. }
  1807. if (G.crc32val != G.lrec.crc32) {
  1808. /* if quiet enough, we haven't output the filename yet: do it */
  1809. if ((uO.tflag && uO.qflag) || (!uO.tflag && !QCOND2))
  1810. Info(slide, 0x401, ((char *)slide, "%-22s ",
  1811. FnFilter1(G.filename)));
  1812. Info(slide, 0x401, ((char *)slide, LoadFarString(BadCRC), G.crc32val,
  1813. G.lrec.crc32));
  1814. #if CRYPT
  1815. if (G.pInfo->encrypted)
  1816. Info(slide, 0x401, ((char *)slide, LoadFarString(MaybeBadPasswd)));
  1817. #endif
  1818. error = PK_ERR;
  1819. } else if (uO.tflag) {
  1820. #ifndef SFX
  1821. if (G.extra_field) {
  1822. if ((r = TestExtraField(__G__ G.extra_field,
  1823. G.lrec.extra_field_length)) > error)
  1824. error = r;
  1825. } else
  1826. #endif /* !SFX */
  1827. if (!uO.qflag)
  1828. Info(slide, 0, ((char *)slide, " OK\n"));
  1829. } else {
  1830. if (QCOND2 && !error) /* GRR: is stdout reset to text mode yet? */
  1831. Info(slide, 0, ((char *)slide, "\n"));
  1832. }
  1833. undefer_input(__G);
  1834. return error;
  1835. } /* end function extract_or_test_member() */
  1836. #ifndef SFX
  1837. /*******************************/
  1838. /* Function TestExtraField() */
  1839. /*******************************/
  1840. static int TestExtraField(__G__ ef, ef_len)
  1841. __GDEF
  1842. uch *ef;
  1843. unsigned ef_len;
  1844. {
  1845. ush ebID;
  1846. unsigned ebLen;
  1847. unsigned eb_cmpr_offs = 0;
  1848. int r;
  1849. /* we know the regular compressed file data tested out OK, or else we
  1850. * wouldn't be here ==> print filename if any extra-field errors found
  1851. */
  1852. while (ef_len >= EB_HEADSIZE) {
  1853. ebID = makeword(ef);
  1854. ebLen = (unsigned)makeword(ef+EB_LEN);
  1855. if (ebLen > (ef_len - EB_HEADSIZE)) {
  1856. /* Discovered some extra field inconsistency! */
  1857. if (uO.qflag)
  1858. Info(slide, 1, ((char *)slide, "%-22s ",
  1859. FnFilter1(G.filename)));
  1860. Info(slide, 1, ((char *)slide, LoadFarString(InconsistEFlength),
  1861. ebLen, (ef_len - EB_HEADSIZE)));
  1862. return PK_ERR;
  1863. }
  1864. switch (ebID) {
  1865. case EF_OS2:
  1866. case EF_ACL:
  1867. case EF_MAC3:
  1868. case EF_BEOS:
  1869. case EF_ATHEOS:
  1870. switch (ebID) {
  1871. case EF_OS2:
  1872. case EF_ACL:
  1873. eb_cmpr_offs = EB_OS2_HLEN;
  1874. break;
  1875. case EF_MAC3:
  1876. if (ebLen >= EB_MAC3_HLEN &&
  1877. (makeword(ef+(EB_HEADSIZE+EB_FLGS_OFFS))
  1878. & EB_M3_FL_UNCMPR) &&
  1879. (makelong(ef+EB_HEADSIZE) == ebLen - EB_MAC3_HLEN))
  1880. eb_cmpr_offs = 0;
  1881. else
  1882. eb_cmpr_offs = EB_MAC3_HLEN;
  1883. break;
  1884. case EF_BEOS:
  1885. case EF_ATHEOS:
  1886. if (ebLen >= EB_BEOS_HLEN &&
  1887. (*(ef+(EB_HEADSIZE+EB_FLGS_OFFS)) & EB_BE_FL_UNCMPR) &&
  1888. (makelong(ef+EB_HEADSIZE) == ebLen - EB_BEOS_HLEN))
  1889. eb_cmpr_offs = 0;
  1890. else
  1891. eb_cmpr_offs = EB_BEOS_HLEN;
  1892. break;
  1893. }
  1894. if ((r = test_compr_eb(__G__ ef, ebLen, eb_cmpr_offs, NULL))
  1895. != PK_OK) {
  1896. if (uO.qflag)
  1897. Info(slide, 1, ((char *)slide, "%-22s ",
  1898. FnFilter1(G.filename)));
  1899. switch (r) {
  1900. case IZ_EF_TRUNC:
  1901. Info(slide, 1, ((char *)slide,
  1902. LoadFarString(TruncEAs),
  1903. ebLen-(eb_cmpr_offs+EB_CMPRHEADLEN), "\n"));
  1904. break;
  1905. case PK_ERR:
  1906. Info(slide, 1, ((char *)slide,
  1907. LoadFarString(InvalidComprDataEAs)));
  1908. break;
  1909. case PK_MEM3:
  1910. case PK_MEM4:
  1911. Info(slide, 1, ((char *)slide,
  1912. LoadFarString(NotEnoughMemEAs)));
  1913. break;
  1914. default:
  1915. if ((r & 0xff) != PK_ERR)
  1916. Info(slide, 1, ((char *)slide,
  1917. LoadFarString(UnknErrorEAs)));
  1918. else {
  1919. ush m = (ush)(r >> 8);
  1920. if (m == DEFLATED) /* GRR KLUDGE! */
  1921. Info(slide, 1, ((char *)slide,
  1922. LoadFarString(BadCRC_EAs)));
  1923. else
  1924. Info(slide, 1, ((char *)slide,
  1925. LoadFarString(UnknComprMethodEAs), m));
  1926. }
  1927. break;
  1928. }
  1929. return r;
  1930. }
  1931. break;
  1932. case EF_NTSD:
  1933. Trace((stderr, "ebID: %i / ebLen: %u\n", ebID, ebLen));
  1934. r = ebLen < EB_NTSD_L_LEN ? IZ_EF_TRUNC :
  1935. ((ef[EB_HEADSIZE+EB_NTSD_VERSION] > EB_NTSD_MAX_VER) ?
  1936. (PK_WARN | 0x4000) :
  1937. test_compr_eb(__G__ ef, ebLen, EB_NTSD_L_LEN, TEST_NTSD));
  1938. if (r != PK_OK) {
  1939. if (uO.qflag)
  1940. Info(slide, 1, ((char *)slide, "%-22s ",
  1941. FnFilter1(G.filename)));
  1942. switch (r) {
  1943. case IZ_EF_TRUNC:
  1944. Info(slide, 1, ((char *)slide,
  1945. LoadFarString(TruncNTSD),
  1946. ebLen-(EB_NTSD_L_LEN+EB_CMPRHEADLEN), "\n"));
  1947. break;
  1948. #if (defined(WIN32) && defined(NTSD_EAS))
  1949. case PK_WARN:
  1950. Info(slide, 1, ((char *)slide,
  1951. LoadFarString(InvalidSecurityEAs)));
  1952. break;
  1953. #endif
  1954. case PK_ERR:
  1955. Info(slide, 1, ((char *)slide,
  1956. LoadFarString(InvalidComprDataEAs)));
  1957. break;
  1958. case PK_MEM3:
  1959. case PK_MEM4:
  1960. Info(slide, 1, ((char *)slide,
  1961. LoadFarString(NotEnoughMemEAs)));
  1962. break;
  1963. case (PK_WARN | 0x4000):
  1964. Info(slide, 1, ((char *)slide,
  1965. LoadFarString(UnsuppNTSDVersEAs),
  1966. (int)ef[EB_HEADSIZE+EB_NTSD_VERSION]));
  1967. r = PK_WARN;
  1968. break;
  1969. default:
  1970. if ((r & 0xff) != PK_ERR)
  1971. Info(slide, 1, ((char *)slide,
  1972. LoadFarString(UnknErrorEAs)));
  1973. else {
  1974. ush m = (ush)(r >> 8);
  1975. if (m == DEFLATED) /* GRR KLUDGE! */
  1976. Info(slide, 1, ((char *)slide,
  1977. LoadFarString(BadCRC_EAs)));
  1978. else
  1979. Info(slide, 1, ((char *)slide,
  1980. LoadFarString(UnknComprMethodEAs), m));
  1981. }
  1982. break;
  1983. }
  1984. return r;
  1985. }
  1986. break;
  1987. case EF_PKVMS:
  1988. if (makelong(ef+EB_HEADSIZE) !=
  1989. crc32(CRCVAL_INITIAL, ef+(EB_HEADSIZE+4),
  1990. (extent)(ebLen-4)))
  1991. Info(slide, 1, ((char *)slide,
  1992. LoadFarString(BadCRC_EAs)));
  1993. break;
  1994. case EF_PKW32:
  1995. case EF_PKUNIX:
  1996. case EF_ASIUNIX:
  1997. case EF_IZVMS:
  1998. case EF_IZUNIX:
  1999. case EF_VMCMS:
  2000. case EF_MVS:
  2001. case EF_SPARK:
  2002. case EF_TANDEM:
  2003. case EF_THEOS:
  2004. case EF_AV:
  2005. default:
  2006. break;
  2007. }
  2008. ef_len -= (ebLen + EB_HEADSIZE);
  2009. ef += (ebLen + EB_HEADSIZE);
  2010. }
  2011. if (!uO.qflag)
  2012. Info(slide, 0, ((char *)slide, " OK\n"));
  2013. return PK_COOL;
  2014. } /* end function TestExtraField() */
  2015. /******************************/
  2016. /* Function test_compr_eb() */
  2017. /******************************/
  2018. #ifdef PROTO
  2019. static int test_compr_eb(
  2020. __GPRO__
  2021. uch *eb,
  2022. unsigned eb_size,
  2023. unsigned compr_offset,
  2024. int (*test_uc_ebdata)(__GPRO__ uch *eb, unsigned eb_size,
  2025. uch *eb_ucptr, ulg eb_ucsize))
  2026. #else /* !PROTO */
  2027. static int test_compr_eb(__G__ eb, eb_size, compr_offset, test_uc_ebdata)
  2028. __GDEF
  2029. uch *eb;
  2030. unsigned eb_size;
  2031. unsigned compr_offset;
  2032. int (*test_uc_ebdata)();
  2033. #endif /* ?PROTO */
  2034. {
  2035. ulg eb_ucsize;
  2036. uch *eb_ucptr;
  2037. int r;
  2038. if (compr_offset < 4) /* field is not compressed: */
  2039. return PK_OK; /* do nothing and signal OK */
  2040. if ((eb_size < (EB_UCSIZE_P + 4)) ||
  2041. ((eb_ucsize = makelong(eb+(EB_HEADSIZE+EB_UCSIZE_P))) > 0L &&
  2042. eb_size <= (compr_offset + EB_CMPRHEADLEN)))
  2043. return IZ_EF_TRUNC; /* no compressed data! */
  2044. if (
  2045. #ifdef INT_16BIT
  2046. (((ulg)(extent)eb_ucsize) != eb_ucsize) ||
  2047. #endif
  2048. (eb_ucptr = (uch *)malloc((extent)eb_ucsize)) == (uch *)NULL)
  2049. return PK_MEM4;
  2050. r = memextract(__G__ eb_ucptr, eb_ucsize,
  2051. eb + (EB_HEADSIZE + compr_offset),
  2052. (ulg)(eb_size - compr_offset));
  2053. if (r == PK_OK && test_uc_ebdata != NULL)
  2054. r = (*test_uc_ebdata)(__G__ eb, eb_size, eb_ucptr, eb_ucsize);
  2055. free(eb_ucptr);
  2056. return r;
  2057. } /* end function test_compr_eb() */
  2058. #endif /* !SFX */
  2059. /***************************/
  2060. /* Function memextract() */
  2061. /***************************/
  2062. int memextract(__G__ tgt, tgtsize, src, srcsize) /* extract compressed */
  2063. __GDEF /* extra field block; */
  2064. uch *tgt; /* return PK-type error */
  2065. ulg tgtsize; /* level */
  2066. ZCONST uch *src;
  2067. ulg srcsize;
  2068. {
  2069. zoff_t old_csize=G.csize;
  2070. uch *old_inptr=G.inptr;
  2071. int old_incnt=G.incnt;
  2072. int r, error=PK_OK;
  2073. ush method;
  2074. ulg extra_field_crc;
  2075. method = makeword(src);
  2076. extra_field_crc = makelong(src+2);
  2077. /* compressed extra field exists completely in memory at this location: */
  2078. G.inptr = (uch *)src + (2 + 4); /* method and extra_field_crc */
  2079. G.incnt = (int)(G.csize = (long)(srcsize - (2 + 4)));
  2080. G.mem_mode = TRUE;
  2081. G.outbufptr = tgt;
  2082. G.outsize = tgtsize;
  2083. switch (method) {
  2084. case STORED:
  2085. memcpy((char *)tgt, (char *)G.inptr, (extent)G.incnt);
  2086. G.outcnt = (ulg)G.csize; /* for CRC calculation */
  2087. break;
  2088. case DEFLATED:
  2089. #ifdef USE_DEFLATE64
  2090. case ENHDEFLATED:
  2091. #endif
  2092. G.outcnt = 0L;
  2093. if ((r = UZinflate(__G__ (method == ENHDEFLATED))) != 0) {
  2094. if (!uO.tflag)
  2095. Info(slide, 0x401, ((char *)slide,
  2096. LoadFarStringSmall(ErrUnzipNoFile), r == 3?
  2097. LoadFarString(NotEnoughMem) :
  2098. LoadFarString(InvalidComprData),
  2099. LoadFarStringSmall2(Inflate)));
  2100. error = (r == 3)? PK_MEM3 : PK_ERR;
  2101. }
  2102. if (G.outcnt == 0L) /* inflate's final FLUSH sets outcnt */
  2103. break;
  2104. break;
  2105. default:
  2106. if (uO.tflag)
  2107. error = PK_ERR | ((int)method << 8);
  2108. else {
  2109. Info(slide, 0x401, ((char *)slide,
  2110. LoadFarString(UnsupportedExtraField), method));
  2111. error = PK_ERR; /* GRR: should be passed on up via SetEAs() */
  2112. }
  2113. break;
  2114. }
  2115. G.inptr = old_inptr;
  2116. G.incnt = old_incnt;
  2117. G.csize = old_csize;
  2118. G.mem_mode = FALSE;
  2119. if (!error) {
  2120. register ulg crcval = crc32(CRCVAL_INITIAL, tgt, (extent)G.outcnt);
  2121. if (crcval != extra_field_crc) {
  2122. if (uO.tflag)
  2123. error = PK_ERR | (DEFLATED << 8); /* kludge for now */
  2124. else {
  2125. Info(slide, 0x401, ((char *)slide,
  2126. LoadFarString(BadExtraFieldCRC), G.zipfn, crcval,
  2127. extra_field_crc));
  2128. error = PK_ERR;
  2129. }
  2130. }
  2131. }
  2132. return error;
  2133. } /* end function memextract() */
  2134. /*************************/
  2135. /* Function memflush() */
  2136. /*************************/
  2137. int memflush(__G__ rawbuf, size)
  2138. __GDEF
  2139. ZCONST uch *rawbuf;
  2140. ulg size;
  2141. {
  2142. if (size > G.outsize)
  2143. /* Here, PK_DISK is a bit off-topic, but in the sense of marking
  2144. "overflow of output space", its use may be tolerated. */
  2145. return PK_DISK; /* more data than output buffer can hold */
  2146. memcpy((char *)G.outbufptr, (char *)rawbuf, (extent)size);
  2147. G.outbufptr += (unsigned int)size;
  2148. G.outsize -= size;
  2149. G.outcnt += size;
  2150. return 0;
  2151. } /* end function memflush() */
  2152. #if (defined(VMS) || defined(VMS_TEXT_CONV))
  2153. /************************************/
  2154. /* Function extract_izvms_block() */
  2155. /************************************/
  2156. /*
  2157. * Extracts block from p. If resulting length is less than needed, fill
  2158. * extra space with corresponding bytes from 'init'.
  2159. * Currently understands 3 formats of block compression:
  2160. * - Simple storing
  2161. * - Compression of zero bytes to zero bits
  2162. * - Deflation (see memextract())
  2163. * The IZVMS block data is returned in malloc'd space.
  2164. */
  2165. uch *extract_izvms_block(__G__ ebdata, size, retlen, init, needlen)
  2166. __GDEF
  2167. ZCONST uch *ebdata;
  2168. unsigned size;
  2169. unsigned *retlen;
  2170. ZCONST uch *init;
  2171. unsigned needlen;
  2172. {
  2173. uch *ucdata; /* Pointer to block allocated */
  2174. int cmptype;
  2175. unsigned usiz, csiz;
  2176. cmptype = (makeword(ebdata+EB_IZVMS_FLGS) & EB_IZVMS_BCMASK);
  2177. csiz = size - EB_IZVMS_HLEN;
  2178. usiz = (cmptype == EB_IZVMS_BCSTOR ?
  2179. csiz : makeword(ebdata+EB_IZVMS_UCSIZ));
  2180. if (retlen)
  2181. *retlen = usiz;
  2182. if ((ucdata = (uch *)malloc(MAX(needlen, usiz))) == NULL)
  2183. return NULL;
  2184. if (init && (usiz < needlen))
  2185. memcpy((char *)ucdata, (ZCONST char *)init, needlen);
  2186. switch (cmptype)
  2187. {
  2188. case EB_IZVMS_BCSTOR: /* The simplest case */
  2189. memcpy(ucdata, ebdata+EB_IZVMS_HLEN, usiz);
  2190. break;
  2191. case EB_IZVMS_BC00:
  2192. decompress_bits(ucdata, usiz, ebdata+EB_IZVMS_HLEN);
  2193. break;
  2194. case EB_IZVMS_BCDEFL:
  2195. memextract(__G__ ucdata, (ulg)usiz,
  2196. ebdata+EB_IZVMS_HLEN, (ulg)csiz);
  2197. break;
  2198. default:
  2199. free(ucdata);
  2200. ucdata = NULL;
  2201. }
  2202. return ucdata;
  2203. } /* end of extract_izvms_block */
  2204. /********************************/
  2205. /* Function decompress_bits() */
  2206. /********************************/
  2207. /*
  2208. * Simple uncompression routine. The compression uses bit stream.
  2209. * Compression scheme:
  2210. *
  2211. * if (byte!=0)
  2212. * putbit(1),putbyte(byte)
  2213. * else
  2214. * putbit(0)
  2215. */
  2216. static void decompress_bits(outptr, needlen, bitptr)
  2217. uch *outptr; /* Pointer into output block */
  2218. unsigned needlen; /* Size of uncompressed block */
  2219. ZCONST uch *bitptr; /* Pointer into compressed data */
  2220. {
  2221. ulg bitbuf = 0;
  2222. int bitcnt = 0;
  2223. #define _FILL { bitbuf |= (*bitptr++) << bitcnt;\
  2224. bitcnt += 8; \
  2225. }
  2226. while (needlen--)
  2227. {
  2228. if (bitcnt <= 0)
  2229. _FILL;
  2230. if (bitbuf & 1)
  2231. {
  2232. bitbuf >>= 1;
  2233. if ((bitcnt -= 1) < 8)
  2234. _FILL;
  2235. *outptr++ = (uch)bitbuf;
  2236. bitcnt -= 8;
  2237. bitbuf >>= 8;
  2238. }
  2239. else
  2240. {
  2241. *outptr++ = '\0';
  2242. bitcnt -= 1;
  2243. bitbuf >>= 1;
  2244. }
  2245. }
  2246. } /* end function decompress_bits() */
  2247. #endif /* VMS || VMS_TEXT_CONV */
  2248. #ifdef SYMLINKS
  2249. /***********************************/
  2250. /* Function set_deferred_symlink() */
  2251. /***********************************/
  2252. static void set_deferred_symlink(__G__ slnk_entry)
  2253. __GDEF
  2254. slinkentry *slnk_entry;
  2255. {
  2256. extent ucsize = slnk_entry->targetlen;
  2257. char *linkfname = slnk_entry->fname;
  2258. char *linktarget = (char *)malloc(ucsize+1);
  2259. if (!linktarget) {
  2260. Info(slide, 0x201, ((char *)slide,
  2261. LoadFarString(SymLnkWarnNoMem), FnFilter1(linkfname)));
  2262. return;
  2263. }
  2264. linktarget[ucsize] = '\0';
  2265. G.outfile = zfopen(linkfname, FOPR); /* open link placeholder for reading */
  2266. /* Check that the following conditions are all fulfilled:
  2267. * a) the placeholder file exists,
  2268. * b) the placeholder file contains exactly "ucsize" bytes
  2269. * (read the expected placeholder content length + 1 extra byte, this
  2270. * should return the expected content length),
  2271. * c) the placeholder content matches the link target specification as
  2272. * stored in the symlink control structure.
  2273. */
  2274. if (!G.outfile ||
  2275. fread(linktarget, 1, ucsize+1, G.outfile) != ucsize ||
  2276. strcmp(slnk_entry->target, linktarget))
  2277. {
  2278. Info(slide, 0x201, ((char *)slide,
  2279. LoadFarString(SymLnkWarnInvalid), FnFilter1(linkfname)));
  2280. free(linktarget);
  2281. if (G.outfile)
  2282. fclose(G.outfile);
  2283. return;
  2284. }
  2285. fclose(G.outfile); /* close "data" file for good... */
  2286. unlink(linkfname); /* ...and delete it */
  2287. if (QCOND2)
  2288. Info(slide, 0, ((char *)slide, LoadFarString(SymLnkFinish),
  2289. FnFilter1(linkfname), FnFilter2(linktarget)));
  2290. if (symlink(linktarget, linkfname)) /* create the real link */
  2291. perror("symlink error");
  2292. free(linktarget);
  2293. #ifdef SET_SYMLINK_ATTRIBS
  2294. set_symlnk_attribs(__G__ slnk_entry);
  2295. #endif
  2296. return; /* can't set time on symlinks */
  2297. } /* end function set_deferred_symlink() */
  2298. #endif /* SYMLINKS */
  2299. /*************************/
  2300. /* Function fnfilter() */ /* here instead of in list.c for SFX */
  2301. /*************************/
  2302. char *fnfilter(raw, space, size) /* convert name to safely printable form */
  2303. ZCONST char *raw;
  2304. uch *space;
  2305. extent size;
  2306. {
  2307. #ifndef NATIVE /* ASCII: filter ANSI escape codes, etc. */
  2308. ZCONST uch *r=(ZCONST uch *)raw;
  2309. uch *s=space;
  2310. uch *slim=NULL;
  2311. uch *se=NULL;
  2312. int have_overflow = FALSE;
  2313. if (size > 0) {
  2314. slim = space + size
  2315. #ifdef _MBCS
  2316. - (MB_CUR_MAX - 1)
  2317. #endif
  2318. - 4;
  2319. }
  2320. while (*r) {
  2321. if (size > 0 && s >= slim && se == NULL) {
  2322. se = s;
  2323. }
  2324. #ifdef QDOS
  2325. if (qlflag & 2) {
  2326. if (*r == '/' || *r == '.') {
  2327. if (se != NULL && (s > (space + (size-3)))) {
  2328. have_overflow = TRUE;
  2329. break;
  2330. }
  2331. ++r;
  2332. *s++ = '_';
  2333. continue;
  2334. }
  2335. } else
  2336. #endif
  2337. #ifdef HAVE_WORKING_ISPRINT
  2338. # ifndef UZ_FNFILTER_REPLACECHAR
  2339. /* A convenient choice for the replacement of unprintable char codes is
  2340. * the "single char wildcard", as this character is quite unlikely to
  2341. * appear in filenames by itself. The following default definition
  2342. * sets the replacement char to a question mark as the most common
  2343. * "single char wildcard"; this setting should be overridden in the
  2344. * appropiate system-specific configuration header when needed.
  2345. */
  2346. # define UZ_FNFILTER_REPLACECHAR '?'
  2347. # endif
  2348. if (!isprint(*r)) {
  2349. if (*r < 32) {
  2350. /* ASCII control codes are escaped as "^{letter}". */
  2351. if (se != NULL && (s > (space + (size-4)))) {
  2352. have_overflow = TRUE;
  2353. break;
  2354. }
  2355. *s++ = '^', *s++ = (uch)(64 + *r++);
  2356. } else {
  2357. /* Other unprintable codes are replaced by the
  2358. * placeholder character. */
  2359. if (se != NULL && (s > (space + (size-3)))) {
  2360. have_overflow = TRUE;
  2361. break;
  2362. }
  2363. *s++ = UZ_FNFILTER_REPLACECHAR;
  2364. INCSTR(r);
  2365. }
  2366. #else /* !HAVE_WORKING_ISPRINT */
  2367. if (*r < 32) {
  2368. /* ASCII control codes are escaped as "^{letter}". */
  2369. if (se != NULL && (s > (space + (size-4)))) {
  2370. have_overflow = TRUE;
  2371. break;
  2372. }
  2373. *s++ = '^', *s++ = (uch)(64 + *r++);
  2374. #endif /* ?HAVE_WORKING_ISPRINT */
  2375. } else {
  2376. #ifdef _MBCS
  2377. unsigned i = CLEN(r);
  2378. if (se != NULL && (s > (space + (size-i-2)))) {
  2379. have_overflow = TRUE;
  2380. break;
  2381. }
  2382. for (; i > 0; i--)
  2383. *s++ = *r++;
  2384. #else
  2385. if (se != NULL && (s > (space + (size-3)))) {
  2386. have_overflow = TRUE;
  2387. break;
  2388. }
  2389. *s++ = *r++;
  2390. #endif
  2391. }
  2392. }
  2393. if (have_overflow) {
  2394. strcpy((char *)se, "...");
  2395. } else {
  2396. *s = '\0';
  2397. }
  2398. #ifdef WINDLL
  2399. INTERN_TO_ISO((char *)space, (char *)space); /* translate to ANSI */
  2400. #else
  2401. #if (defined(WIN32) && !defined(_WIN32_WCE))
  2402. /* Win9x console always uses OEM character coding, and
  2403. WinNT console is set to OEM charset by default, too */
  2404. INTERN_TO_OEM((char *)space, (char *)space);
  2405. #endif /* (WIN32 && !_WIN32_WCE) */
  2406. #endif /* ?WINDLL */
  2407. return (char *)space;
  2408. #else /* NATIVE: EBCDIC or whatever */
  2409. return (char *)raw;
  2410. #endif
  2411. } /* end function fnfilter() */
  2412. #ifdef SET_DIR_ATTRIB
  2413. /* must sort saved directories so can set perms from bottom up */
  2414. /************************/
  2415. /* Function dircomp() */
  2416. /************************/
  2417. static int Cdecl dircomp(a, b) /* used by qsort(); swiped from Zip */
  2418. ZCONST zvoid *a, *b;
  2419. {
  2420. /* order is significant: this sorts in reverse order (deepest first) */
  2421. return strcmp((*(direntry **)b)->fn, (*(direntry **)a)->fn);
  2422. /* return namecmp((*(direntry **)b)->fn, (*(direntry **)a)->fn); */
  2423. }
  2424. #endif /* SET_DIR_ATTRIB */
  2425. #ifdef USE_BZIP2
  2426. /**************************/
  2427. /* Function UZbunzip2() */
  2428. /**************************/
  2429. int UZbunzip2(__G)
  2430. __GDEF
  2431. /* decompress a bzipped entry using the libbz2 routines */
  2432. {
  2433. int retval = 0; /* return code: 0 = "no error" */
  2434. int err=BZ_OK;
  2435. int repeated_buf_err;
  2436. bz_stream bstrm;
  2437. #if (defined(DLL) && !defined(NO_SLIDE_REDIR))
  2438. if (G.redirect_slide)
  2439. wsize = G.redirect_size, redirSlide = G.redirect_buffer;
  2440. else
  2441. wsize = WSIZE, redirSlide = slide;
  2442. #endif
  2443. bstrm.next_out = (char *)redirSlide;
  2444. bstrm.avail_out = wsize;
  2445. bstrm.next_in = (char *)G.inptr;
  2446. bstrm.avail_in = G.incnt;
  2447. {
  2448. /* local buffer for efficiency */
  2449. /* $TODO Check for BZIP LIB version? */
  2450. bstrm.bzalloc = NULL;
  2451. bstrm.bzfree = NULL;
  2452. bstrm.opaque = NULL;
  2453. Trace((stderr, "initializing bzlib()\n"));
  2454. err = BZ2_bzDecompressInit(&bstrm, 0, 0);
  2455. if (err == BZ_MEM_ERROR)
  2456. return 3;
  2457. else if (err != BZ_OK)
  2458. Trace((stderr, "oops! (BZ2_bzDecompressInit() err = %d)\n", err));
  2459. }
  2460. #ifdef FUNZIP
  2461. while (err != BZ_STREAM_END) {
  2462. #else /* !FUNZIP */
  2463. while (G.csize > 0) {
  2464. Trace((stderr, "first loop: G.csize = %ld\n", G.csize));
  2465. #endif /* ?FUNZIP */
  2466. while (bstrm.avail_out > 0) {
  2467. err = BZ2_bzDecompress(&bstrm);
  2468. if (err == BZ_DATA_ERROR) {
  2469. retval = 2; goto uzbunzip_cleanup_exit;
  2470. } else if (err == BZ_MEM_ERROR) {
  2471. retval = 3; goto uzbunzip_cleanup_exit;
  2472. } else if (err != BZ_OK && err != BZ_STREAM_END)
  2473. Trace((stderr, "oops! (bzip(first loop) err = %d)\n", err));
  2474. #ifdef FUNZIP
  2475. if (err == BZ_STREAM_END) /* "END-of-entry-condition" ? */
  2476. #else /* !FUNZIP */
  2477. if (G.csize <= 0L) /* "END-of-entry-condition" ? */
  2478. #endif /* ?FUNZIP */
  2479. break;
  2480. if (bstrm.avail_in == 0) {
  2481. if (fillinbuf(__G) == 0) {
  2482. /* no "END-condition" yet, but no more data */
  2483. retval = 2; goto uzbunzip_cleanup_exit;
  2484. }
  2485. bstrm.next_in = (char *)G.inptr;
  2486. bstrm.avail_in = G.incnt;
  2487. }
  2488. Trace((stderr, " avail_in = %u\n", bstrm.avail_in));
  2489. }
  2490. /* flush slide[] */
  2491. if ((retval = FLUSH(wsize - bstrm.avail_out)) != 0)
  2492. goto uzbunzip_cleanup_exit;
  2493. Trace((stderr, "inside loop: flushing %ld bytes (ptr diff = %ld)\n",
  2494. (long)(wsize - bstrm.avail_out),
  2495. (long)(bstrm.next_out-(char *)redirSlide)));
  2496. bstrm.next_out = (char *)redirSlide;
  2497. bstrm.avail_out = wsize;
  2498. }
  2499. /* no more input, so loop until we have all output */
  2500. Trace((stderr, "beginning final loop: err = %d\n", err));
  2501. repeated_buf_err = FALSE;
  2502. while (err != BZ_STREAM_END) {
  2503. err = BZ2_bzDecompress(&bstrm);
  2504. if (err == BZ_DATA_ERROR) {
  2505. retval = 2; goto uzbunzip_cleanup_exit;
  2506. } else if (err == BZ_MEM_ERROR) {
  2507. retval = 3; goto uzbunzip_cleanup_exit;
  2508. } else if (err != BZ_OK && err != BZ_STREAM_END) {
  2509. Trace((stderr, "oops! (bzip(final loop) err = %d)\n", err));
  2510. DESTROYGLOBALS();
  2511. EXIT(PK_MEM3);
  2512. }
  2513. /* final flush of slide[] */
  2514. if ((retval = FLUSH(wsize - bstrm.avail_out)) != 0)
  2515. goto uzbunzip_cleanup_exit;
  2516. Trace((stderr, "final loop: flushing %ld bytes (ptr diff = %ld)\n",
  2517. (long)(wsize - bstrm.avail_out),
  2518. (long)(bstrm.next_out-(char *)redirSlide)));
  2519. bstrm.next_out = (char *)redirSlide;
  2520. bstrm.avail_out = wsize;
  2521. }
  2522. #ifdef LARGE_FILE_SUPPORT
  2523. Trace((stderr, "total in = %llu, total out = %llu\n",
  2524. (zusz_t)(bstrm.total_in_lo32) + ((zusz_t)(bstrm.total_in_hi32))<<32,
  2525. (zusz_t)(bstrm.total_out_lo32) + ((zusz_t)(bstrm.total_out_hi32))<<32));
  2526. #else
  2527. Trace((stderr, "total in = %lu, total out = %lu\n", bstrm.total_in_lo32,
  2528. bstrm.total_out_lo32));
  2529. #endif
  2530. G.inptr = (uch *)bstrm.next_in;
  2531. G.incnt = (G.inbuf + INBUFSIZ) - G.inptr; /* reset for other routines */
  2532. uzbunzip_cleanup_exit:
  2533. err = BZ2_bzDecompressEnd(&bstrm);
  2534. if (err != BZ_OK)
  2535. Trace((stderr, "oops! (BZ2_bzDecompressEnd() err = %d)\n", err));
  2536. return retval;
  2537. } /* end function UZbunzip2() */
  2538. #endif /* USE_BZIP2 */