gzip 1.3.5
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 6 Oct 1999 05:00:00 +0000 (05:00 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 6 Oct 1999 05:00:00 +0000 (05:00 +0000)
bits.c
lzw.c
trees.c
unlzh.c
unpack.c
unzip.c

diff --git a/bits.c b/bits.c
index 2949ad5d9516c4c0d2b5e648c9bbd05d895cf102..3745a9ef31976ff2843fdf4fc55e5ea6e0cf9c34 100644 (file)
--- a/bits.c
+++ b/bits.c
@@ -51,6 +51,7 @@
  *
  */
 
+#include <config.h>
 #include "tailor.h"
 #include "gzip.h"
 #include "crypt.h"
@@ -88,7 +89,7 @@ int (*read_buf) OF((char *buf, unsigned size));
 /* Current input function. Set to mem_read for in-memory compression */
 
 #ifdef DEBUG
-  ulg bits_sent;   /* bit length of the compressed data */
+  off_t bits_sent;   /* bit length of the compressed data */
 #endif
 
 /* ===========================================================================
@@ -123,7 +124,7 @@ void send_bits(value, length)
 #ifdef DEBUG
     Tracev((stderr," l %2d v %4x ", length, value));
     Assert(length > 0 && length <= 15, "invalid length");
-    bits_sent += (ulg)length;
+    bits_sent += (off_t)length;
 #endif
     /* If not enough room in bi_buf, use (valid) bits from bi_buf and
      * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
@@ -193,7 +194,7 @@ void copy_block(buf, len, header)
 #endif
     }
 #ifdef DEBUG
-    bits_sent += (ulg)len<<3;
+    bits_sent += (off_t)len<<3;
 #endif
     while (len--) {
 #ifdef CRYPT
diff --git a/lzw.c b/lzw.c
index eb67d46e8b7fc1dc694dec68f5c25f8994d58bbc..0dc2fe063440cccc3de767cbf19cf755de8601fd 100644 (file)
--- a/lzw.c
+++ b/lzw.c
@@ -6,6 +6,7 @@
 static char rcsid[] = "$Id$";
 #endif
 
+#include <config.h>
 #include "tailor.h"
 #include "gzip.h"
 #include "lzw.h"
diff --git a/trees.c b/trees.c
index 27396a0d027484fd970d2a7425c8e62fc10384b5..8ee3b988ac77ba4622cb50ba79820646c0eb905b 100644 (file)
--- a/trees.c
+++ b/trees.c
  *      void ct_tally (int dist, int lc);
  *          Save the match info and tally the frequency counts.
  *
- *      long flush_block (char *buf, ulg stored_len, int eof)
+ *      off_t flush_block (char *buf, ulg stored_len, int eof)
  *          Determine the best encoding for the current block: dynamic trees,
  *          static trees or store, and output the encoded block to the zip
  *          file. Returns the total compressed length for the file so far.
  *
  */
 
+#include <config.h>
 #include <ctype.h>
 
 #include "tailor.h"
@@ -271,17 +272,16 @@ local uch flag_bit;         /* current bit used in flags */
 local ulg opt_len;        /* bit length of current block with optimal trees */
 local ulg static_len;     /* bit length of current block with static trees */
 
-local ulg compressed_len; /* total bit length of compressed file */
+local off_t compressed_len; /* total bit length of compressed file */
 
-local ulg input_len;      /* total byte length of input file */
+local off_t input_len;      /* total byte length of input file */
 /* input_len is for debugging only since we can get it by other means. */
 
 ush *file_type;        /* pointer to UNKNOWN, BINARY or ASCII */
 int *file_method;      /* pointer to DEFLATE or STORE */
 
 #ifdef DEBUG
-extern ulg bits_sent;  /* bit length of the compressed data */
-extern long isize;     /* byte length of input file */
+extern off_t bits_sent;  /* bit length of the compressed data */
 #endif
 
 extern long block_start;       /* window offset of current block */
@@ -810,7 +810,7 @@ local int build_bl_tree()
     }
     /* Update opt_len to include the bit length tree and counts */
     opt_len += 3*(max_blindex+1) + 5+5+4;
-    Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", opt_len, static_len));
+    Tracev((stderr, "\ndyn trees: dyn %lu, stat %lu", opt_len, static_len));
 
     return max_blindex;
 }
@@ -836,13 +836,10 @@ local void send_all_trees(lcodes, dcodes, blcodes)
         Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
         send_bits(bl_tree[bl_order[rank]].Len, 3);
     }
-    Tracev((stderr, "\nbl tree: sent %ld", bits_sent));
 
     send_tree((ct_data near *)dyn_ltree, lcodes-1); /* send the literal tree */
-    Tracev((stderr, "\nlit tree: sent %ld", bits_sent));
 
     send_tree((ct_data near *)dyn_dtree, dcodes-1); /* send the distance tree */
-    Tracev((stderr, "\ndist tree: sent %ld", bits_sent));
 }
 
 /* ===========================================================================
@@ -850,7 +847,7 @@ local void send_all_trees(lcodes, dcodes, blcodes)
  * trees or store, and output the encoded block to the zip file. This function
  * returns the total compressed length for the file so far.
  */
-ulg flush_block(buf, stored_len, eof)
+off_t flush_block(buf, stored_len, eof)
     char *buf;        /* input block, or NULL if too old */
     ulg stored_len;   /* length of input block */
     int eof;          /* true if this is the last block for a file */
@@ -865,10 +862,10 @@ ulg flush_block(buf, stored_len, eof)
 
     /* Construct the literal and distance trees */
     build_tree((tree_desc near *)(&l_desc));
-    Tracev((stderr, "\nlit data: dyn %ld, stat %ld", opt_len, static_len));
+    Tracev((stderr, "\nlit data: dyn %lu, stat %lu", opt_len, static_len));
 
     build_tree((tree_desc near *)(&d_desc));
-    Tracev((stderr, "\ndist data: dyn %ld, stat %ld", opt_len, static_len));
+    Tracev((stderr, "\ndist data: dyn %lu, stat %lu", opt_len, static_len));
     /* At this point, opt_len and static_len are the total bit lengths of
      * the compressed block data, excluding the tree representations.
      */
@@ -941,12 +938,10 @@ ulg flush_block(buf, stored_len, eof)
     init_block();
 
     if (eof) {
-        Assert (input_len == isize, "bad input size");
+        Assert (input_len == bytes_in, "bad input size");
         bi_windup();
         compressed_len += 7;  /* align on byte boundary */
     }
-    Tracev((stderr,"\ncomprlen %lu(%lu) ", compressed_len>>3,
-           compressed_len-7*eof));
 
     return compressed_len >> 3;
 }
@@ -1070,6 +1065,6 @@ local void set_file_type()
     while (n < LITERALS) bin_freq += dyn_ltree[n++].Freq;
     *file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII;
     if (*file_type == BINARY && translate_eol) {
-        warn("-l used on binary file", "");
+        warning ("-l used on binary file");
     }
 }
diff --git a/unlzh.c b/unlzh.c
index f6399115255d133242bcd3cb2298619a3af6b919..148c417907dc7c116ad905353106a8fde6dcd0f2 100644 (file)
--- a/unlzh.c
+++ b/unlzh.c
@@ -7,6 +7,7 @@
 static char rcsid[] = "$Id$";
 #endif
 
+#include <config.h>
 #include <stdio.h>
 
 #include "tailor.h"
index a9bc18e7e1779aa15fe4ede3688ccd9bfe0200cb..358788ed0e6761a1dcd17ab5ad0905cb68ece635 100644 (file)
--- a/unpack.c
+++ b/unpack.c
@@ -8,6 +8,7 @@
 static char rcsid[] = "$Id$";
 #endif
 
+#include <config.h>
 #include "tailor.h"
 #include "gzip.h"
 #include "crypt.h"
@@ -115,7 +116,7 @@ local void read_tree()
     if (n > LITERALS) {
        error("too many leaves in Huffman tree");
     }
-    Trace((stderr, "orig_len %ld, max_len %d, leaves %d\n",
+    Trace((stderr, "orig_len %lu, max_len %d, leaves %d\n",
           orig_len, max_len, n));
     /* There are at least 2 and at most 256 leaves of length max_len.
      * (Pack arbitrarily rejects empty files and files consisting of
@@ -231,8 +232,7 @@ int unpack(in, out)
     } /* for (;;) */
 
     flush_window();
-    Trace((stderr, "bytes_out %ld\n", bytes_out));
-    if (orig_len != (ulg)bytes_out) {
+    if (orig_len != (ulg)(bytes_out & 0xffffffff)) {
        error("invalid compressed data--length error");
     }
     return OK;
diff --git a/unzip.c b/unzip.c
index cd3d50e5a05a26427c333e630f213c9329dbdb34..db3e3ac3cb09e5041f2abc96e5ffb0797a0fbd39 100644 (file)
--- a/unzip.c
+++ b/unzip.c
@@ -17,6 +17,7 @@
 static char rcsid[] = "$Id$";
 #endif
 
+#include <config.h>
 #include "tailor.h"
 #include "gzip.h"
 #include "crypt.h"
@@ -35,6 +36,7 @@ static char rcsid[] = "$Id$";
 #define LOCEXT 28               /* offset of extra field length */
 #define LOCHDR 30               /* size of local header, including sig */
 #define EXTHDR 16               /* size of extended local header, inc sig */
+#define RAND_HEAD_LEN  12       /* length of encryption random header */
 
 
 /* Globals */
@@ -103,6 +105,7 @@ int unzip(in, out)
     ulg orig_len = 0;       /* original uncompressed length */
     int n;
     uch buf[EXTHDR];        /* extended local header */
+    int err = OK;
 
     ifd = in;
     ofd = out;
@@ -136,9 +139,6 @@ int unzip(in, out)
        }
        while (n--) {
            uch c = (uch)get_byte();
-#ifdef CRYPT
-           if (decrypt) zdecode(c);
-#endif
            put_ubyte(c);
        }
        flush_window();
@@ -172,10 +172,14 @@ int unzip(in, out)
 
     /* Validate decompression */
     if (orig_crc != updcrc(outbuf, 0)) {
-       error("invalid compressed data--crc error");
+       fprintf(stderr, "\n%s: %s: invalid compressed data--crc error\n",
+               progname, ifname);
+       err = ERROR;
     }
-    if (orig_len != (ulg)bytes_out) {
-       error("invalid compressed data--length error");
+    if (orig_len != (ulg)(bytes_out & 0xffffffff)) {
+       fprintf(stderr, "\n%s: %s: invalid compressed data--length error\n",
+               progname, ifname);
+       err = ERROR;
     }
 
     /* Check if there are more entries in a pkzip file */
@@ -189,11 +193,12 @@ int unzip(in, out)
            fprintf(stderr,
                    "%s: %s has more than one entry -- unchanged\n",
                    progname, ifname);
-           exit_code = ERROR;
-           ext_header = pkzip = 0;
-           return ERROR;
+           err = ERROR;
        }
     }
     ext_header = pkzip = 0; /* for next file */
-    return OK;
+    if (err == OK) return OK;
+    exit_code = ERROR;
+    if (!test) abort_gzip();
+    return err;
 }