From d9a513aab586c69e2b87b3ed1fa12b22c5632e4f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 6 Oct 1999 05:00:00 +0000 Subject: [PATCH] gzip 1.3.5 --- bits.c | 7 ++++--- lzw.c | 1 + trees.c | 27 +++++++++++---------------- unlzh.c | 1 + unpack.c | 6 +++--- unzip.c | 25 +++++++++++++++---------- 6 files changed, 35 insertions(+), 32 deletions(-) diff --git a/bits.c b/bits.c index 2949ad5..3745a9e 100644 --- a/bits.c +++ b/bits.c @@ -51,6 +51,7 @@ * */ +#include #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 eb67d46..0dc2fe0 100644 --- a/lzw.c +++ b/lzw.c @@ -6,6 +6,7 @@ static char rcsid[] = "$Id$"; #endif +#include #include "tailor.h" #include "gzip.h" #include "lzw.h" diff --git a/trees.c b/trees.c index 27396a0..8ee3b98 100644 --- a/trees.c +++ b/trees.c @@ -46,13 +46,14 @@ * 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 #include #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 f639911..148c417 100644 --- a/unlzh.c +++ b/unlzh.c @@ -7,6 +7,7 @@ static char rcsid[] = "$Id$"; #endif +#include #include #include "tailor.h" diff --git a/unpack.c b/unpack.c index a9bc18e..358788e 100644 --- a/unpack.c +++ b/unpack.c @@ -8,6 +8,7 @@ static char rcsid[] = "$Id$"; #endif +#include #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 cd3d50e..db3e3ac 100644 --- a/unzip.c +++ b/unzip.c @@ -17,6 +17,7 @@ static char rcsid[] = "$Id$"; #endif +#include #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; } -- 2.47.2