diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-05-18 13:08:57 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-05-18 13:08:57 +0200 |
commit | 167cd709df06fb0f7aa346a32133d54ed3ae6c48 (patch) | |
tree | 5594aac275c132c15beecad47f3bf067578ac90f | |
parent | 16bda3bd1f8e486ed93f5182fc777be1e813bce7 (diff) | |
download | busybox-w32-167cd709df06fb0f7aa346a32133d54ed3ae6c48.tar.gz busybox-w32-167cd709df06fb0f7aa346a32133d54ed3ae6c48.tar.bz2 busybox-w32-167cd709df06fb0f7aa346a32133d54ed3ae6c48.zip |
gzip: fix gzip with many files corrupting some files after first
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/gzip.c | 70 |
1 files changed, 32 insertions, 38 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index a8f8fa4a5..335846908 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -267,7 +267,7 @@ struct globals { | |||
267 | #define DECLARE(type, array, size) \ | 267 | #define DECLARE(type, array, size) \ |
268 | type * array | 268 | type * array |
269 | #define ALLOC(type, array, size) \ | 269 | #define ALLOC(type, array, size) \ |
270 | array = xzalloc((size_t)(((size)+1L)/2) * 2*sizeof(type)); | 270 | array = xzalloc((size_t)(((size)+1L)/2) * 2*sizeof(type)) |
271 | #define FREE(array) \ | 271 | #define FREE(array) \ |
272 | do { free(array); array = NULL; } while (0) | 272 | do { free(array); array = NULL; } while (0) |
273 | 273 | ||
@@ -389,19 +389,6 @@ static void put_32bit(ulg n) | |||
389 | } | 389 | } |
390 | 390 | ||
391 | /* =========================================================================== | 391 | /* =========================================================================== |
392 | * Clear input and output buffers | ||
393 | */ | ||
394 | static void clear_bufs(void) | ||
395 | { | ||
396 | G1.outcnt = 0; | ||
397 | #ifdef DEBUG | ||
398 | G1.insize = 0; | ||
399 | #endif | ||
400 | G1.isize = 0; | ||
401 | } | ||
402 | |||
403 | |||
404 | /* =========================================================================== | ||
405 | * Run a set of bytes through the crc shift register. If s is a NULL | 392 | * Run a set of bytes through the crc shift register. If s is a NULL |
406 | * pointer, then initialize the crc shift register contents instead. | 393 | * pointer, then initialize the crc shift register contents instead. |
407 | * Return the current crc in either case. | 394 | * Return the current crc in either case. |
@@ -2019,7 +2006,37 @@ IF_DESKTOP(long long) int pack_gzip(unpack_info_t *info UNUSED_PARAM) | |||
2019 | { | 2006 | { |
2020 | struct stat s; | 2007 | struct stat s; |
2021 | 2008 | ||
2022 | clear_bufs(); | 2009 | /* Clear input and output buffers */ |
2010 | G1.outcnt = 0; | ||
2011 | #ifdef DEBUG | ||
2012 | G1.insize = 0; | ||
2013 | #endif | ||
2014 | G1.isize = 0; | ||
2015 | |||
2016 | /* Reinit G2.xxx */ | ||
2017 | memset(&G2, 0, sizeof(G2)); | ||
2018 | G2.l_desc.dyn_tree = G2.dyn_ltree; | ||
2019 | G2.l_desc.static_tree = G2.static_ltree; | ||
2020 | G2.l_desc.extra_bits = extra_lbits; | ||
2021 | G2.l_desc.extra_base = LITERALS + 1; | ||
2022 | G2.l_desc.elems = L_CODES; | ||
2023 | G2.l_desc.max_length = MAX_BITS; | ||
2024 | //G2.l_desc.max_code = 0; | ||
2025 | G2.d_desc.dyn_tree = G2.dyn_dtree; | ||
2026 | G2.d_desc.static_tree = G2.static_dtree; | ||
2027 | G2.d_desc.extra_bits = extra_dbits; | ||
2028 | //G2.d_desc.extra_base = 0; | ||
2029 | G2.d_desc.elems = D_CODES; | ||
2030 | G2.d_desc.max_length = MAX_BITS; | ||
2031 | //G2.d_desc.max_code = 0; | ||
2032 | G2.bl_desc.dyn_tree = G2.bl_tree; | ||
2033 | //G2.bl_desc.static_tree = NULL; | ||
2034 | G2.bl_desc.extra_bits = extra_blbits, | ||
2035 | //G2.bl_desc.extra_base = 0; | ||
2036 | G2.bl_desc.elems = BL_CODES; | ||
2037 | G2.bl_desc.max_length = MAX_BL_BITS; | ||
2038 | //G2.bl_desc.max_code = 0; | ||
2039 | |||
2023 | s.st_ctime = 0; | 2040 | s.st_ctime = 0; |
2024 | fstat(STDIN_FILENO, &s); | 2041 | fstat(STDIN_FILENO, &s); |
2025 | zip(s.st_ctime); | 2042 | zip(s.st_ctime); |
@@ -2064,29 +2081,6 @@ int gzip_main(int argc UNUSED_PARAM, char **argv) | |||
2064 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(struct globals) + sizeof(struct globals2)) | 2081 | SET_PTR_TO_GLOBALS(xzalloc(sizeof(struct globals) + sizeof(struct globals2)) |
2065 | + sizeof(struct globals)); | 2082 | + sizeof(struct globals)); |
2066 | barrier(); | 2083 | barrier(); |
2067 | G2.l_desc.dyn_tree = G2.dyn_ltree; | ||
2068 | G2.l_desc.static_tree = G2.static_ltree; | ||
2069 | G2.l_desc.extra_bits = extra_lbits; | ||
2070 | G2.l_desc.extra_base = LITERALS + 1; | ||
2071 | G2.l_desc.elems = L_CODES; | ||
2072 | G2.l_desc.max_length = MAX_BITS; | ||
2073 | //G2.l_desc.max_code = 0; | ||
2074 | |||
2075 | G2.d_desc.dyn_tree = G2.dyn_dtree; | ||
2076 | G2.d_desc.static_tree = G2.static_dtree; | ||
2077 | G2.d_desc.extra_bits = extra_dbits; | ||
2078 | //G2.d_desc.extra_base = 0; | ||
2079 | G2.d_desc.elems = D_CODES; | ||
2080 | G2.d_desc.max_length = MAX_BITS; | ||
2081 | //G2.d_desc.max_code = 0; | ||
2082 | |||
2083 | G2.bl_desc.dyn_tree = G2.bl_tree; | ||
2084 | //G2.bl_desc.static_tree = NULL; | ||
2085 | G2.bl_desc.extra_bits = extra_blbits, | ||
2086 | //G2.bl_desc.extra_base = 0; | ||
2087 | G2.bl_desc.elems = BL_CODES; | ||
2088 | G2.bl_desc.max_length = MAX_BL_BITS; | ||
2089 | //G2.bl_desc.max_code = 0; | ||
2090 | 2084 | ||
2091 | /* Allocate all global buffers (for DYN_ALLOC option) */ | 2085 | /* Allocate all global buffers (for DYN_ALLOC option) */ |
2092 | ALLOC(uch, G1.l_buf, INBUFSIZ); | 2086 | ALLOC(uch, G1.l_buf, INBUFSIZ); |