funzip.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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. /* funzip.c -- by Mark Adler */
  9. #define VERSION "3.95 of 20 January 2009"
  10. /* Copyright history:
  11. - Starting with UnZip 5.41 of 16-April-2000, this source file
  12. is covered by the Info-Zip LICENSE cited above.
  13. - Prior versions of this source file, found in UnZip source packages
  14. up to UnZip 5.40, were put in the public domain.
  15. The original copyright note by Mark Adler was:
  16. "You can do whatever you like with this source file,
  17. though I would prefer that if you modify it and
  18. redistribute it that you include comments to that effect
  19. with your name and the date. Thank you."
  20. History:
  21. vers date who what
  22. ---- --------- -------------- ------------------------------------
  23. 1.0 13 Aug 92 M. Adler really simple unzip filter.
  24. 1.1 13 Aug 92 M. Adler cleaned up somewhat, give help if
  25. stdin not redirected, warn if more
  26. zip file entries after the first.
  27. 1.2 15 Aug 92 M. Adler added check of lengths for stored
  28. entries, added more help.
  29. 1.3 16 Aug 92 M. Adler removed redundant #define's, added
  30. decryption.
  31. 1.4 27 Aug 92 G. Roelofs added exit(0).
  32. 1.5 1 Sep 92 K. U. Rommel changed read/write modes for OS/2.
  33. 1.6 6 Sep 92 G. Roelofs modified to use dummy crypt.c and
  34. crypt.h instead of -DCRYPT.
  35. 1.7 23 Sep 92 G. Roelofs changed to use DOS_OS2; included
  36. crypt.c under MS-DOS.
  37. 1.8 9 Oct 92 M. Adler improved inflation error msgs.
  38. 1.9 17 Oct 92 G. Roelofs changed ULONG/UWORD/byte to ulg/ush/uch;
  39. renamed inflate_entry() to inflate();
  40. adapted to use new, in-place zdecode.
  41. 2.0 22 Oct 92 M. Adler allow filename argument, prompt for
  42. passwords and don't echo, still allow
  43. command-line password entry, but as an
  44. option.
  45. 2.1 23 Oct 92 J-l. Gailly fixed crypt/store bug,
  46. G. Roelofs removed crypt.c under MS-DOS, fixed
  47. decryption check to compare single byte.
  48. 2.2 28 Oct 92 G. Roelofs removed declaration of key.
  49. 2.3 14 Dec 92 M. Adler replaced fseek (fails on stdin for SCO
  50. Unix V.3.2.4). added quietflg for
  51. inflate.c.
  52. 3.0 11 May 93 M. Adler added gzip support
  53. 3.1 9 Jul 93 K. U. Rommel fixed OS/2 pipe bug (PIPE_ERROR)
  54. 3.2 4 Sep 93 G. Roelofs moved crc_32_tab[] to tables.h; used FOPx
  55. from unzip.h; nuked OUTB macro and outbuf;
  56. replaced flush(); inlined FlushOutput();
  57. renamed decrypt to encrypted
  58. 3.3 29 Sep 93 G. Roelofs replaced ReadByte() with NEXTBYTE macro;
  59. revised (restored?) flush(); added FUNZIP
  60. 3.4 21 Oct 93 G. Roelofs renamed quietflg to qflag; changed outcnt,
  61. H. Gessau second updcrc() arg and flush() arg to ulg;
  62. added inflate_free(); added "g =" to null
  63. getc(in) to avoid compiler warnings
  64. 3.5 31 Oct 93 H. Gessau changed DOS_OS2 to DOS_NT_OS2
  65. 3.6 6 Dec 93 H. Gessau added "near" to mask_bits[]
  66. 3.7 9 Dec 93 G. Roelofs added extent typecasts to fwrite() checks
  67. 3.8 28 Jan 94 GRR/JlG initialized g variable in main() for gcc
  68. 3.81 22 Feb 94 M. Hanning-Lee corrected usage message
  69. 3.82 27 Feb 94 G. Roelofs added some typecasts to avoid warnings
  70. 3.83 22 Jul 94 G. Roelofs changed fprintf to macro for DLLs
  71. - 2 Aug 94 - public release with UnZip 5.11
  72. - 28 Aug 94 - public release with UnZip 5.12
  73. 3.84 1 Oct 94 K. U. Rommel changes for Metaware High C
  74. 3.85 29 Oct 94 G. Roelofs changed fprintf macro to Info
  75. 3.86 7 May 95 K. Davis RISCOS patches;
  76. P. Kienitz Amiga patches
  77. 3.87 12 Aug 95 G. Roelofs inflate_free(), DESTROYGLOBALS fixes
  78. 3.88 4 Sep 95 C. Spieler reordered macro to work around MSC 5.1 bug
  79. 3.89 22 Nov 95 PK/CS ifdef'd out updcrc() for ASM_CRC
  80. 3.9 17 Dec 95 G. Roelofs modified for USE_ZLIB (new fillinbuf())
  81. - 30 Apr 96 - public release with UnZip 5.2
  82. 3.91 17 Aug 96 G. Roelofs main() -> return int (Peter Seebach)
  83. 3.92 13 Apr 97 G. Roelofs minor cosmetic fixes to messages
  84. - 22 Apr 97 - public release with UnZip 5.3
  85. - 31 May 97 - public release with UnZip 5.31
  86. 3.93 20 Sep 97 G. Roelofs minor cosmetic fixes to messages
  87. - 3 Nov 97 - public release with UnZip 5.32
  88. - 28 Nov 98 - public release with UnZip 5.4
  89. - 16 Apr 00 - public release with UnZip 5.41
  90. - 14 Jan 01 - public release with UnZip 5.42
  91. 3.94 20 Feb 01 C. Spieler added support for Deflate64(tm)
  92. 23 Mar 02 C. Spieler changed mask_bits[] type to "unsigned"
  93. */
  94. /*
  95. All funzip does is take a zipfile from stdin and decompress the
  96. first entry to stdout. The entry has to be either deflated or
  97. stored. If the entry is encrypted, then the decryption password
  98. must be supplied on the command line as the first argument.
  99. funzip needs to be linked with inflate.o and crypt.o compiled from
  100. the unzip source. If decryption is desired, the full version of
  101. crypt.c (and crypt.h) from zcrypt28.zip or later must be used.
  102. */
  103. #ifndef FUNZIP
  104. # define FUNZIP
  105. #endif
  106. #define UNZIP_INTERNAL
  107. #include "unzip.h"
  108. #include "crc32.h"
  109. #include "crypt.h"
  110. #include "ttyio.h"
  111. #ifdef EBCDIC
  112. # undef EBCDIC /* don't need ebcdic[] */
  113. #endif
  114. #ifndef USE_ZLIB /* zlib's function is called inflate(), too */
  115. # define UZinflate inflate
  116. #endif
  117. /* PKZIP header definitions */
  118. #define ZIPMAG 0x4b50 /* two-byte zip lead-in */
  119. #define LOCREM 0x0403 /* remaining two bytes in zip signature */
  120. #define LOCSIG 0x04034b50L /* full signature */
  121. #define LOCFLG 4 /* offset of bit flag */
  122. #define CRPFLG 1 /* bit for encrypted entry */
  123. #define EXTFLG 8 /* bit for extended local header */
  124. #define LOCHOW 6 /* offset of compression method */
  125. #define LOCTIM 8 /* file mod time (for decryption) */
  126. #define LOCCRC 12 /* offset of crc */
  127. #define LOCSIZ 16 /* offset of compressed size */
  128. #define LOCLEN 20 /* offset of uncompressed length */
  129. #define LOCFIL 24 /* offset of file name field length */
  130. #define LOCEXT 26 /* offset of extra field length */
  131. #define LOCHDR 28 /* size of local header, including LOCREM */
  132. #define EXTHDR 16 /* size of extended local header, inc sig */
  133. /* GZIP header definitions */
  134. #define GZPMAG 0x8b1f /* two-byte gzip lead-in */
  135. #define GZPHOW 0 /* offset of method number */
  136. #define GZPFLG 1 /* offset of gzip flags */
  137. #define GZPMUL 2 /* bit for multiple-part gzip file */
  138. #define GZPISX 4 /* bit for extra field present */
  139. #define GZPISF 8 /* bit for filename present */
  140. #define GZPISC 16 /* bit for comment present */
  141. #define GZPISE 32 /* bit for encryption */
  142. #define GZPTIM 2 /* offset of Unix file modification time */
  143. #define GZPEXF 6 /* offset of extra flags */
  144. #define GZPCOS 7 /* offset of operating system compressed on */
  145. #define GZPHDR 8 /* length of minimal gzip header */
  146. #ifdef THEOS
  147. /* Macros cause stack overflow in compiler */
  148. ush SH(uch* p) { return ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8)); }
  149. ulg LG(uch* p) { return ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16)); }
  150. #else /* !THEOS */
  151. /* Macros for getting two-byte and four-byte header values */
  152. #define SH(p) ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8))
  153. #define LG(p) ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16))
  154. #endif /* ?THEOS */
  155. /* Function prototypes */
  156. static void err OF((int, char *));
  157. #if (defined(USE_DEFLATE64) && defined(__16BIT__))
  158. static int partflush OF((uch *rawbuf, unsigned w));
  159. #endif
  160. int main OF((int, char **));
  161. /* Globals */
  162. FILE *out; /* output file (*in moved to G struct) */
  163. ulg outsiz; /* total bytes written to out */
  164. int encrypted; /* flag to turn on decryption */
  165. /* Masks for inflate.c */
  166. ZCONST unsigned near mask_bits[17] = {
  167. 0x0000,
  168. 0x0001, 0x0003, 0x0007, 0x000f, 0x001f, 0x003f, 0x007f, 0x00ff,
  169. 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff
  170. };
  171. #ifdef USE_ZLIB
  172. int fillinbuf(__G)
  173. __GDEF
  174. /* Fill input buffer for pull-model inflate() in zlib. Return the number of
  175. * bytes in inbuf. */
  176. {
  177. /* GRR: check return value from fread(): same as read()? check errno? */
  178. if ((G.incnt = fread((char *)G.inbuf, 1, INBUFSIZ, G.in)) <= 0)
  179. return 0;
  180. G.inptr = G.inbuf;
  181. #if CRYPT
  182. if (encrypted) {
  183. uch *p;
  184. int n;
  185. for (n = G.incnt, p = G.inptr; n--; p++)
  186. zdecode(*p);
  187. }
  188. #endif /* CRYPT */
  189. return G.incnt;
  190. }
  191. #endif /* USE_ZLIB */
  192. static void err(n, m)
  193. int n;
  194. char *m;
  195. /* Exit on error with a message and a code */
  196. {
  197. Info(slide, 1, ((char *)slide, "funzip error: %s\n", m));
  198. DESTROYGLOBALS();
  199. EXIT(n);
  200. }
  201. #if (defined(USE_DEFLATE64) && defined(__16BIT__))
  202. static int partflush(rawbuf, w)
  203. uch *rawbuf; /* start of buffer area to flush */
  204. extent w; /* number of bytes to flush */
  205. {
  206. G.crc32val = crc32(G.crc32val, rawbuf, (extent)w);
  207. if (fwrite((char *)rawbuf,1,(extent)w,out) != (extent)w && !PIPE_ERROR)
  208. err(9, "out of space on stdout");
  209. outsiz += w;
  210. return 0;
  211. }
  212. int flush(w) /* used by inflate.c (FLUSH macro) */
  213. ulg w; /* number of bytes to flush */
  214. {
  215. uch *rawbuf;
  216. int ret;
  217. /* On 16-bit systems (MSDOS, OS/2 1.x), the standard C library functions
  218. * cannot handle writes of 64k blocks at once. For these systems, the
  219. * blocks to flush are split into pieces of 32k or less.
  220. */
  221. rawbuf = slide;
  222. while (w > 0x8000L) {
  223. ret = partflush(rawbuf, 0x8000);
  224. if (ret != PK_OK)
  225. return ret;
  226. w -= 0x8000L;
  227. rawbuf += (unsigned)0x8000;
  228. }
  229. return partflush(rawbuf, (extent)w);
  230. } /* end function flush() */
  231. #else /* !(USE_DEFLATE64 && __16BIT__) */
  232. int flush(w) /* used by inflate.c (FLUSH macro) */
  233. ulg w; /* number of bytes to flush */
  234. {
  235. G.crc32val = crc32(G.crc32val, slide, (extent)w);
  236. if (fwrite((char *)slide,1,(extent)w,out) != (extent)w && !PIPE_ERROR)
  237. err(9, "out of space on stdout");
  238. outsiz += w;
  239. return 0;
  240. }
  241. #endif /* ?(USE_DEFLATE64 && __16BIT__) */
  242. int main(argc, argv)
  243. int argc;
  244. char **argv;
  245. /* Given a zipfile on stdin, decompress the first entry to stdout. */
  246. {
  247. ush n;
  248. uch h[LOCHDR]; /* first local header (GZPHDR < LOCHDR) */
  249. int g = 0; /* true if gzip format */
  250. unsigned method = 0; /* initialized here to shut up gcc warning */
  251. #if CRYPT
  252. char *s = " [-password]";
  253. char *p; /* password */
  254. #else /* !CRYPT */
  255. char *s = "";
  256. #endif /* ?CRYPT */
  257. CONSTRUCTGLOBALS();
  258. /* skip executable name */
  259. argc--;
  260. argv++;
  261. #if CRYPT
  262. /* get the command line password, if any */
  263. p = (char *)NULL;
  264. if (argc && **argv == '-')
  265. {
  266. argc--;
  267. p = 1 + *argv++;
  268. }
  269. #endif /* CRYPT */
  270. #ifdef MALLOC_WORK
  271. /* The following expression is a cooked-down simplyfication of the
  272. calculation for the work area size of UnZip (see unzip.c). For
  273. fUnZip, the work area does not need to match the granularity
  274. of the complex unshrink structures, because it only supports
  275. inflation. But, like in UnZip, the zcalloc() wrapper function
  276. is needed for the allocation, to support the 64kByte buffer on
  277. 16-bit systems.
  278. */
  279. # define UZ_SLIDE_CHUNK (sizeof(shrint)+sizeof(uch)+sizeof(uch))
  280. # define UZ_NUMOF_CHUNKS (unsigned)( (WSIZE+UZ_SLIDE_CHUNK-1)/UZ_SLIDE_CHUNK )
  281. G.area.Slide = (uch *)zcalloc(UZ_NUMOF_CHUNKS, UZ_SLIDE_CHUNK);
  282. # undef UZ_SLIDE_CHUNK
  283. # undef UZ_NUMOF_CHUNKS
  284. #endif
  285. /* if no file argument and stdin not redirected, give the user help */
  286. if (argc == 0 && isatty(0))
  287. {
  288. Info(slide, 1, ((char *)slide, "fUnZip (filter UnZip), version %s\n",
  289. VERSION));
  290. Info(slide, 1, ((char *)slide, "usage: ... | funzip%s | ...\n", s));
  291. Info(slide, 1, ((char *)slide, " ... | funzip%s > outfile\n", s));
  292. Info(slide, 1, ((char *)slide, " funzip%s infile.zip > outfile\n",s));
  293. Info(slide, 1, ((char *)slide, " funzip%s infile.gz > outfile\n", s));
  294. Info(slide, 1, ((char *)slide, "Extracts to stdout the gzip file or first\
  295. zip entry of stdin or the given file.\n"));
  296. DESTROYGLOBALS();
  297. EXIT(3);
  298. }
  299. /* prepare to be a binary filter */
  300. if (argc)
  301. {
  302. if ((G.in = fopen(*argv, FOPR)) == (FILE *)NULL)
  303. err(2, "cannot find input file");
  304. }
  305. else
  306. {
  307. #ifdef DOS_FLX_NLM_OS2_W32
  308. #if (defined(__HIGHC__) && !defined(FLEXOS))
  309. setmode(stdin, _BINARY);
  310. #else
  311. setmode(0, O_BINARY); /* some buggy C libraries require BOTH setmode() */
  312. #endif /* call AND the fdopen() in binary mode :-( */
  313. #endif /* DOS_FLX_NLM_OS2_W32 */
  314. #ifdef RISCOS
  315. G.in = stdin;
  316. #else
  317. if ((G.in = fdopen(0, FOPR)) == (FILE *)NULL)
  318. err(2, "cannot find stdin");
  319. #endif
  320. }
  321. #ifdef DOS_FLX_H68_NLM_OS2_W32
  322. #if (defined(__HIGHC__) && !defined(FLEXOS))
  323. setmode(stdout, _BINARY);
  324. #else
  325. setmode(1, O_BINARY);
  326. #endif
  327. #endif /* DOS_FLX_H68_NLM_OS2_W32 */
  328. #ifdef RISCOS
  329. out = stdout;
  330. #else
  331. if ((out = fdopen(1, FOPW)) == (FILE *)NULL)
  332. err(2, "cannot write to stdout");
  333. #endif
  334. /* read local header, check validity, and skip name and extra fields */
  335. n = getc(G.in); n |= getc(G.in) << 8;
  336. if (n == ZIPMAG)
  337. {
  338. if (fread((char *)h, 1, LOCHDR, G.in) != LOCHDR || SH(h) != LOCREM)
  339. err(3, "invalid zipfile");
  340. switch (method = SH(h + LOCHOW)) {
  341. case STORED:
  342. case DEFLATED:
  343. #ifdef USE_DEFLATE64
  344. case ENHDEFLATED:
  345. #endif
  346. break;
  347. default:
  348. err(3, "first entry not deflated or stored--cannot unpack");
  349. break;
  350. }
  351. for (n = SH(h + LOCFIL); n--; ) g = getc(G.in);
  352. for (n = SH(h + LOCEXT); n--; ) g = getc(G.in);
  353. g = 0;
  354. encrypted = h[LOCFLG] & CRPFLG;
  355. }
  356. else if (n == GZPMAG)
  357. {
  358. if (fread((char *)h, 1, GZPHDR, G.in) != GZPHDR)
  359. err(3, "invalid gzip file");
  360. if ((method = h[GZPHOW]) != DEFLATED && method != ENHDEFLATED)
  361. err(3, "gzip file not deflated");
  362. if (h[GZPFLG] & GZPMUL)
  363. err(3, "cannot handle multi-part gzip files");
  364. if (h[GZPFLG] & GZPISX)
  365. {
  366. n = getc(G.in); n |= getc(G.in) << 8;
  367. while (n--) g = getc(G.in);
  368. }
  369. if (h[GZPFLG] & GZPISF)
  370. while ((g = getc(G.in)) != 0 && g != EOF) ;
  371. if (h[GZPFLG] & GZPISC)
  372. while ((g = getc(G.in)) != 0 && g != EOF) ;
  373. g = 1;
  374. encrypted = h[GZPFLG] & GZPISE;
  375. }
  376. else
  377. err(3, "input not a zip or gzip file");
  378. /* if entry encrypted, decrypt and validate encryption header */
  379. if (encrypted)
  380. #if CRYPT
  381. {
  382. ush i, e;
  383. if (p == (char *)NULL) {
  384. if ((p = (char *)malloc(IZ_PWLEN+1)) == (char *)NULL)
  385. err(1, "out of memory");
  386. else if ((p = getp("Enter password: ", p, IZ_PWLEN+1)) == (char *)NULL)
  387. err(1, "no tty to prompt for password");
  388. }
  389. /* initialize crc_32_tab pointer for decryption */
  390. CRC_32_TAB = get_crc_table();
  391. /* prepare the decryption keys for extraction and check the password */
  392. init_keys(p);
  393. for (i = 0; i < RAND_HEAD_LEN; i++)
  394. e = NEXTBYTE;
  395. if (e != (ush)(h[LOCFLG] & EXTFLG ? h[LOCTIM + 1] : h[LOCCRC + 3]))
  396. err(3, "incorrect password for first entry");
  397. }
  398. #else /* !CRYPT */
  399. err(3, "cannot decrypt entry (need to recompile with full crypt.c)");
  400. #endif /* ?CRYPT */
  401. /* prepare output buffer and crc */
  402. G.outptr = slide;
  403. G.outcnt = 0L;
  404. outsiz = 0L;
  405. G.crc32val = CRCVAL_INITIAL;
  406. /* decompress */
  407. if (g || h[LOCHOW])
  408. { /* deflated entry */
  409. int r;
  410. #ifdef USE_ZLIB
  411. /* need to allocate and prepare input buffer */
  412. if ((G.inbuf = (uch *)malloc(INBUFSIZ)) == (uch *)NULL)
  413. err(1, "out of memory");
  414. #endif /* USE_ZLIB */
  415. if ((r = UZinflate(__G__ (method == ENHDEFLATED))) != 0) {
  416. if (r == 3)
  417. err(1, "out of memory");
  418. else
  419. err(4, "invalid compressed data--format violated");
  420. }
  421. inflate_free(__G);
  422. }
  423. else
  424. { /* stored entry */
  425. register ulg n;
  426. n = LG(h + LOCLEN);
  427. #if CRYPT
  428. if (n != LG(h + LOCSIZ) - (encrypted ? RAND_HEAD_LEN : 0)) {
  429. #else
  430. if (n != LG(h + LOCSIZ)) {
  431. #endif
  432. Info(slide, 1, ((char *)slide, "len %ld, siz %ld\n", n, LG(h + LOCSIZ)));
  433. err(4, "invalid compressed data--length mismatch");
  434. }
  435. while (n--) {
  436. ush c = getc(G.in);
  437. #if CRYPT
  438. if (encrypted)
  439. zdecode(c);
  440. #endif
  441. *G.outptr++ = (uch)c;
  442. #if (defined(USE_DEFLATE64) && defined(__16BIT__))
  443. if (++G.outcnt == (WSIZE>>1)) /* do FlushOutput() */
  444. #else
  445. if (++G.outcnt == WSIZE) /* do FlushOutput() */
  446. #endif
  447. {
  448. G.crc32val = crc32(G.crc32val, slide, (extent)G.outcnt);
  449. if (fwrite((char *)slide, 1,(extent)G.outcnt,out) != (extent)G.outcnt
  450. && !PIPE_ERROR)
  451. err(9, "out of space on stdout");
  452. outsiz += G.outcnt;
  453. G.outptr = slide;
  454. G.outcnt = 0L;
  455. }
  456. }
  457. }
  458. if (G.outcnt) /* flush one last time; no need to reset G.outptr/outcnt */
  459. {
  460. G.crc32val = crc32(G.crc32val, slide, (extent)G.outcnt);
  461. if (fwrite((char *)slide, 1,(extent)G.outcnt,out) != (extent)G.outcnt
  462. && !PIPE_ERROR)
  463. err(9, "out of space on stdout");
  464. outsiz += G.outcnt;
  465. }
  466. fflush(out);
  467. /* if extended header, get it */
  468. if (g)
  469. {
  470. if (fread((char *)h + LOCCRC, 1, 8, G.in) != 8)
  471. err(3, "gzip file ended prematurely");
  472. }
  473. else
  474. if ((h[LOCFLG] & EXTFLG) &&
  475. fread((char *)h + LOCCRC - 4, 1, EXTHDR, G.in) != EXTHDR)
  476. err(3, "zipfile ended prematurely");
  477. /* validate decompression */
  478. if (LG(h + LOCCRC) != G.crc32val)
  479. err(4, "invalid compressed data--crc error");
  480. if (LG((g ? (h + LOCSIZ) : (h + LOCLEN))) != outsiz)
  481. err(4, "invalid compressed data--length error");
  482. /* check if there are more entries */
  483. if (!g && fread((char *)h, 1, 4, G.in) == 4 && LG(h) == LOCSIG)
  484. Info(slide, 1, ((char *)slide,
  485. "funzip warning: zipfile has more than one entry--rest ignored\n"));
  486. DESTROYGLOBALS();
  487. RETURN (0);
  488. }