diff options
Diffstat (limited to 'archival')
-rw-r--r-- | archival/bbunzip.c | 2 | ||||
-rw-r--r-- | archival/gzip.c | 130 | ||||
-rw-r--r-- | archival/libarchive/decompress_gunzip.c | 111 | ||||
-rw-r--r-- | archival/libarchive/decompress_unxz.c | 20 | ||||
-rw-r--r-- | archival/libarchive/unxz/xz_stream.h | 2 | ||||
-rw-r--r-- | archival/tar.c | 2 |
6 files changed, 152 insertions, 115 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c index 24033c9f5..da6f031e3 100644 --- a/archival/bbunzip.c +++ b/archival/bbunzip.c | |||
@@ -538,6 +538,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv) | |||
538 | //usage: "\n -c Write to stdout" | 538 | //usage: "\n -c Write to stdout" |
539 | //usage: "\n -f Force" | 539 | //usage: "\n -f Force" |
540 | //usage: "\n -k Keep input files" | 540 | //usage: "\n -k Keep input files" |
541 | //usage: "\n -t Test file integrity" | ||
541 | //usage: | 542 | //usage: |
542 | //usage:#define xz_trivial_usage | 543 | //usage:#define xz_trivial_usage |
543 | //usage: "-d [-cfk] [FILE]..." | 544 | //usage: "-d [-cfk] [FILE]..." |
@@ -547,6 +548,7 @@ int unlzma_main(int argc UNUSED_PARAM, char **argv) | |||
547 | //usage: "\n -c Write to stdout" | 548 | //usage: "\n -c Write to stdout" |
548 | //usage: "\n -f Force" | 549 | //usage: "\n -f Force" |
549 | //usage: "\n -k Keep input files" | 550 | //usage: "\n -k Keep input files" |
551 | //usage: "\n -t Test file integrity" | ||
550 | //usage: | 552 | //usage: |
551 | //usage:#define xzcat_trivial_usage | 553 | //usage:#define xzcat_trivial_usage |
552 | //usage: "[FILE]..." | 554 | //usage: "[FILE]..." |
diff --git a/archival/gzip.c b/archival/gzip.c index 17341de45..d9c730f13 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -52,7 +52,7 @@ aa: 85.1% -- replaced with aa.gz | |||
52 | //config: help | 52 | //config: help |
53 | //config: Enable support for compression levels 4-9. The default level | 53 | //config: Enable support for compression levels 4-9. The default level |
54 | //config: is 6. If levels 1-3 are specified, 4 is used. | 54 | //config: is 6. If levels 1-3 are specified, 4 is used. |
55 | //config: If this option is not selected, -N options are ignored and -9 | 55 | //config: If this option is not selected, -N options are ignored and -6 |
56 | //config: is used. | 56 | //config: is used. |
57 | //config: | 57 | //config: |
58 | //config:config FEATURE_GZIP_DECOMPRESS | 58 | //config:config FEATURE_GZIP_DECOMPRESS |
@@ -259,12 +259,13 @@ enum { | |||
259 | 259 | ||
260 | #if !ENABLE_FEATURE_GZIP_LEVELS | 260 | #if !ENABLE_FEATURE_GZIP_LEVELS |
261 | 261 | ||
262 | max_chain_length = 4096, | 262 | comp_level_minus4 = 6 - 4, |
263 | max_chain_length = 128, | ||
263 | /* To speed up deflation, hash chains are never searched beyond this length. | 264 | /* To speed up deflation, hash chains are never searched beyond this length. |
264 | * A higher limit improves compression ratio but degrades the speed. | 265 | * A higher limit improves compression ratio but degrades the speed. |
265 | */ | 266 | */ |
266 | 267 | ||
267 | max_lazy_match = 258, | 268 | max_lazy_match = 16, |
268 | /* Attempt to find a better match only when the current match is strictly | 269 | /* Attempt to find a better match only when the current match is strictly |
269 | * smaller than this value. This mechanism is used only for compression | 270 | * smaller than this value. This mechanism is used only for compression |
270 | * levels >= 4. | 271 | * levels >= 4. |
@@ -276,7 +277,7 @@ enum { | |||
276 | * max_insert_length is used only for compression levels <= 3. | 277 | * max_insert_length is used only for compression levels <= 3. |
277 | */ | 278 | */ |
278 | 279 | ||
279 | good_match = 32, | 280 | good_match = 8, |
280 | /* Use a faster search when the previous match is longer than this */ | 281 | /* Use a faster search when the previous match is longer than this */ |
281 | 282 | ||
282 | /* Values for max_lazy_match, good_match and max_chain_length, depending on | 283 | /* Values for max_lazy_match, good_match and max_chain_length, depending on |
@@ -285,7 +286,7 @@ enum { | |||
285 | * found for specific files. | 286 | * found for specific files. |
286 | */ | 287 | */ |
287 | 288 | ||
288 | nice_match = 258, /* Stop searching when current match exceeds this */ | 289 | nice_match = 128, /* Stop searching when current match exceeds this */ |
289 | /* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 | 290 | /* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 |
290 | * For deflate_fast() (levels <= 3) good is ignored and lazy has a different | 291 | * For deflate_fast() (levels <= 3) good is ignored and lazy has a different |
291 | * meaning. | 292 | * meaning. |
@@ -334,14 +335,16 @@ struct globals { | |||
334 | #define head (G1.prev + WSIZE) /* hash head (see deflate.c) */ | 335 | #define head (G1.prev + WSIZE) /* hash head (see deflate.c) */ |
335 | 336 | ||
336 | #if ENABLE_FEATURE_GZIP_LEVELS | 337 | #if ENABLE_FEATURE_GZIP_LEVELS |
338 | unsigned comp_level_minus4; /* can be a byte */ | ||
337 | unsigned max_chain_length; | 339 | unsigned max_chain_length; |
338 | unsigned max_lazy_match; | 340 | unsigned max_lazy_match; |
339 | unsigned good_match; | 341 | unsigned good_match; |
340 | unsigned nice_match; | 342 | unsigned nice_match; |
341 | #define max_chain_length (G1.max_chain_length) | 343 | #define comp_level_minus4 (G1.comp_level_minus4) |
342 | #define max_lazy_match (G1.max_lazy_match) | 344 | #define max_chain_length (G1.max_chain_length) |
343 | #define good_match (G1.good_match) | 345 | #define max_lazy_match (G1.max_lazy_match) |
344 | #define nice_match (G1.nice_match) | 346 | #define good_match (G1.good_match) |
347 | #define nice_match (G1.nice_match) | ||
345 | #endif | 348 | #endif |
346 | 349 | ||
347 | /* =========================================================================== */ | 350 | /* =========================================================================== */ |
@@ -504,7 +507,7 @@ static ALWAYS_INLINE void flush_outbuf_if_32bit_optimized(void) | |||
504 | * pointer, then initialize the crc shift register contents instead. | 507 | * pointer, then initialize the crc shift register contents instead. |
505 | * Return the current crc in either case. | 508 | * Return the current crc in either case. |
506 | */ | 509 | */ |
507 | static void updcrc(uch * s, unsigned n) | 510 | static void updcrc(uch *s, unsigned n) |
508 | { | 511 | { |
509 | G1.crc = crc32_block_endian0(G1.crc, s, n, global_crc32_table /*G1.crc_32_tab*/); | 512 | G1.crc = crc32_block_endian0(G1.crc, s, n, global_crc32_table /*G1.crc_32_tab*/); |
510 | } | 513 | } |
@@ -607,7 +610,7 @@ static void bi_windup(void) | |||
607 | * Copy a stored block to the zip file, storing first the length and its | 610 | * Copy a stored block to the zip file, storing first the length and its |
608 | * one's complement if requested. | 611 | * one's complement if requested. |
609 | */ | 612 | */ |
610 | static void copy_block(char *buf, unsigned len, int header) | 613 | static void copy_block(const char *buf, unsigned len, int header) |
611 | { | 614 | { |
612 | bi_windup(); /* align on byte boundary */ | 615 | bi_windup(); /* align on byte boundary */ |
613 | 616 | ||
@@ -1007,7 +1010,8 @@ struct globals2 { | |||
1007 | tree_desc d_desc; | 1010 | tree_desc d_desc; |
1008 | tree_desc bl_desc; | 1011 | tree_desc bl_desc; |
1009 | 1012 | ||
1010 | ush bl_count[MAX_BITS + 1]; | 1013 | /* was "ush", but "unsigned" results in smaller code */ |
1014 | unsigned bl_count[MAX_BITS + 1]; | ||
1011 | 1015 | ||
1012 | /* The lengths of the bit length codes are sent in order of decreasing | 1016 | /* The lengths of the bit length codes are sent in order of decreasing |
1013 | * probability, to avoid transmitting the lengths for unused bit length codes. | 1017 | * probability, to avoid transmitting the lengths for unused bit length codes. |
@@ -1118,7 +1122,7 @@ static void init_block(void) | |||
1118 | (tree[n].Freq < tree[m].Freq \ | 1122 | (tree[n].Freq < tree[m].Freq \ |
1119 | || (tree[n].Freq == tree[m].Freq && G2.depth[n] <= G2.depth[m])) | 1123 | || (tree[n].Freq == tree[m].Freq && G2.depth[n] <= G2.depth[m])) |
1120 | 1124 | ||
1121 | static void pqdownheap(ct_data * tree, int k) | 1125 | static void pqdownheap(const ct_data *tree, int k) |
1122 | { | 1126 | { |
1123 | int v = G2.heap[k]; | 1127 | int v = G2.heap[k]; |
1124 | int j = k << 1; /* left son of k */ | 1128 | int j = k << 1; /* left son of k */ |
@@ -1152,22 +1156,15 @@ static void pqdownheap(ct_data * tree, int k) | |||
1152 | * The length opt_len is updated; static_len is also updated if stree is | 1156 | * The length opt_len is updated; static_len is also updated if stree is |
1153 | * not null. | 1157 | * not null. |
1154 | */ | 1158 | */ |
1155 | static void gen_bitlen(tree_desc * desc) | 1159 | static void gen_bitlen(const tree_desc *desc) |
1156 | { | 1160 | { |
1157 | ct_data *tree = desc->dyn_tree; | 1161 | #define tree desc->dyn_tree |
1158 | const uint8_t *extra = desc->extra_bits; | 1162 | int h; /* heap index */ |
1159 | int base = desc->extra_base; | 1163 | int n, m; /* iterate over the tree elements */ |
1160 | int max_code = desc->max_code; | 1164 | int bits; /* bit length */ |
1161 | int max_length = desc->max_length; | 1165 | int overflow; /* number of elements with bit length too large */ |
1162 | ct_data *stree = desc->static_tree; | 1166 | |
1163 | int h; /* heap index */ | 1167 | for (bits = 0; bits < ARRAY_SIZE(G2.bl_count); bits++) |
1164 | int n, m; /* iterate over the tree elements */ | ||
1165 | int bits; /* bit length */ | ||
1166 | int xbits; /* extra bits */ | ||
1167 | ush f; /* frequency */ | ||
1168 | int overflow = 0; /* number of elements with bit length too large */ | ||
1169 | |||
1170 | for (bits = 0; bits <= MAX_BITS; bits++) | ||
1171 | G2.bl_count[bits] = 0; | 1168 | G2.bl_count[bits] = 0; |
1172 | 1169 | ||
1173 | /* In a first pass, compute the optimal bit lengths (which may | 1170 | /* In a first pass, compute the optimal bit lengths (which may |
@@ -1175,28 +1172,32 @@ static void gen_bitlen(tree_desc * desc) | |||
1175 | */ | 1172 | */ |
1176 | tree[G2.heap[G2.heap_max]].Len = 0; /* root of the heap */ | 1173 | tree[G2.heap[G2.heap_max]].Len = 0; /* root of the heap */ |
1177 | 1174 | ||
1175 | overflow = 0; | ||
1178 | for (h = G2.heap_max + 1; h < HEAP_SIZE; h++) { | 1176 | for (h = G2.heap_max + 1; h < HEAP_SIZE; h++) { |
1177 | ulg f; /* frequency */ | ||
1178 | int xbits; /* extra bits */ | ||
1179 | |||
1179 | n = G2.heap[h]; | 1180 | n = G2.heap[h]; |
1180 | bits = tree[tree[n].Dad].Len + 1; | 1181 | bits = tree[tree[n].Dad].Len + 1; |
1181 | if (bits > max_length) { | 1182 | if (bits > desc->max_length) { |
1182 | bits = max_length; | 1183 | bits = desc->max_length; |
1183 | overflow++; | 1184 | overflow++; |
1184 | } | 1185 | } |
1185 | tree[n].Len = (ush) bits; | 1186 | tree[n].Len = (ush) bits; |
1186 | /* We overwrite tree[n].Dad which is no longer needed */ | 1187 | /* We overwrite tree[n].Dad which is no longer needed */ |
1187 | 1188 | ||
1188 | if (n > max_code) | 1189 | if (n > desc->max_code) |
1189 | continue; /* not a leaf node */ | 1190 | continue; /* not a leaf node */ |
1190 | 1191 | ||
1191 | G2.bl_count[bits]++; | 1192 | G2.bl_count[bits]++; |
1192 | xbits = 0; | 1193 | xbits = 0; |
1193 | if (n >= base) | 1194 | if (n >= desc->extra_base) |
1194 | xbits = extra[n - base]; | 1195 | xbits = desc->extra_bits[n - desc->extra_base]; |
1195 | f = tree[n].Freq; | 1196 | f = tree[n].Freq; |
1196 | G2.opt_len += (ulg) f *(bits + xbits); | 1197 | G2.opt_len += f * (bits + xbits); |
1197 | 1198 | ||
1198 | if (stree) | 1199 | if (desc->static_tree) |
1199 | G2.static_len += (ulg) f * (stree[n].Len + xbits); | 1200 | G2.static_len += f * (desc->static_tree[n].Len + xbits); |
1200 | } | 1201 | } |
1201 | if (overflow == 0) | 1202 | if (overflow == 0) |
1202 | return; | 1203 | return; |
@@ -1206,14 +1207,14 @@ static void gen_bitlen(tree_desc * desc) | |||
1206 | 1207 | ||
1207 | /* Find the first bit length which could increase: */ | 1208 | /* Find the first bit length which could increase: */ |
1208 | do { | 1209 | do { |
1209 | bits = max_length - 1; | 1210 | bits = desc->max_length - 1; |
1210 | while (G2.bl_count[bits] == 0) | 1211 | while (G2.bl_count[bits] == 0) |
1211 | bits--; | 1212 | bits--; |
1212 | G2.bl_count[bits]--; /* move one leaf down the tree */ | 1213 | G2.bl_count[bits]--; /* move one leaf down the tree */ |
1213 | G2.bl_count[bits + 1] += 2; /* move one overflow item as its brother */ | 1214 | G2.bl_count[bits + 1] += 2; /* move one overflow item as its brother */ |
1214 | G2.bl_count[max_length]--; | 1215 | G2.bl_count[desc->max_length]--; |
1215 | /* The brother of the overflow item also moves one step up, | 1216 | /* The brother of the overflow item also moves one step up, |
1216 | * but this does not affect bl_count[max_length] | 1217 | * but this does not affect bl_count[desc->max_length] |
1217 | */ | 1218 | */ |
1218 | overflow -= 2; | 1219 | overflow -= 2; |
1219 | } while (overflow > 0); | 1220 | } while (overflow > 0); |
@@ -1223,11 +1224,11 @@ static void gen_bitlen(tree_desc * desc) | |||
1223 | * lengths instead of fixing only the wrong ones. This idea is taken | 1224 | * lengths instead of fixing only the wrong ones. This idea is taken |
1224 | * from 'ar' written by Haruhiko Okumura.) | 1225 | * from 'ar' written by Haruhiko Okumura.) |
1225 | */ | 1226 | */ |
1226 | for (bits = max_length; bits != 0; bits--) { | 1227 | for (bits = desc->max_length; bits != 0; bits--) { |
1227 | n = G2.bl_count[bits]; | 1228 | n = G2.bl_count[bits]; |
1228 | while (n != 0) { | 1229 | while (n != 0) { |
1229 | m = G2.heap[--h]; | 1230 | m = G2.heap[--h]; |
1230 | if (m > max_code) | 1231 | if (m > desc->max_code) |
1231 | continue; | 1232 | continue; |
1232 | if (tree[m].Len != (unsigned) bits) { | 1233 | if (tree[m].Len != (unsigned) bits) { |
1233 | Trace((stderr, "code %d bits %d->%d\n", m, tree[m].Len, bits)); | 1234 | Trace((stderr, "code %d bits %d->%d\n", m, tree[m].Len, bits)); |
@@ -1237,6 +1238,7 @@ static void gen_bitlen(tree_desc * desc) | |||
1237 | n--; | 1238 | n--; |
1238 | } | 1239 | } |
1239 | } | 1240 | } |
1241 | #undef tree | ||
1240 | } | 1242 | } |
1241 | 1243 | ||
1242 | /* =========================================================================== | 1244 | /* =========================================================================== |
@@ -1247,12 +1249,13 @@ static void gen_bitlen(tree_desc * desc) | |||
1247 | * OUT assertion: the field code is set for all tree elements of non | 1249 | * OUT assertion: the field code is set for all tree elements of non |
1248 | * zero code length. | 1250 | * zero code length. |
1249 | */ | 1251 | */ |
1250 | static void gen_codes(ct_data * tree, int max_code) | 1252 | static void gen_codes(ct_data *tree, int max_code) |
1251 | { | 1253 | { |
1252 | ush next_code[MAX_BITS + 1]; /* next code value for each bit length */ | 1254 | /* next_code[] and code used to be "ush", but "unsigned" results in smaller code */ |
1253 | ush code = 0; /* running code value */ | 1255 | unsigned next_code[MAX_BITS + 1]; /* next code value for each bit length */ |
1254 | int bits; /* bit index */ | 1256 | unsigned code = 0; /* running code value */ |
1255 | int n; /* code index */ | 1257 | int bits; /* bit index */ |
1258 | int n; /* code index */ | ||
1256 | 1259 | ||
1257 | /* The distribution counts are first used to generate the code values | 1260 | /* The distribution counts are first used to generate the code values |
1258 | * without bit reversal. | 1261 | * without bit reversal. |
@@ -1304,7 +1307,7 @@ do { \ | |||
1304 | pqdownheap(tree, SMALLEST); \ | 1307 | pqdownheap(tree, SMALLEST); \ |
1305 | } while (0) | 1308 | } while (0) |
1306 | 1309 | ||
1307 | static void build_tree(tree_desc * desc) | 1310 | static void build_tree(tree_desc *desc) |
1308 | { | 1311 | { |
1309 | ct_data *tree = desc->dyn_tree; | 1312 | ct_data *tree = desc->dyn_tree; |
1310 | ct_data *stree = desc->static_tree; | 1313 | ct_data *stree = desc->static_tree; |
@@ -1382,10 +1385,10 @@ static void build_tree(tree_desc * desc) | |||
1382 | /* At this point, the fields freq and dad are set. We can now | 1385 | /* At this point, the fields freq and dad are set. We can now |
1383 | * generate the bit lengths. | 1386 | * generate the bit lengths. |
1384 | */ | 1387 | */ |
1385 | gen_bitlen((tree_desc *) desc); | 1388 | gen_bitlen(desc); |
1386 | 1389 | ||
1387 | /* The field len is now set, we can generate the bit codes */ | 1390 | /* The field len is now set, we can generate the bit codes */ |
1388 | gen_codes((ct_data *) tree, max_code); | 1391 | gen_codes(tree, max_code); |
1389 | } | 1392 | } |
1390 | 1393 | ||
1391 | /* =========================================================================== | 1394 | /* =========================================================================== |
@@ -1394,7 +1397,7 @@ static void build_tree(tree_desc * desc) | |||
1394 | * counts. (The contribution of the bit length codes will be added later | 1397 | * counts. (The contribution of the bit length codes will be added later |
1395 | * during the construction of bl_tree.) | 1398 | * during the construction of bl_tree.) |
1396 | */ | 1399 | */ |
1397 | static void scan_tree(ct_data * tree, int max_code) | 1400 | static void scan_tree(ct_data *tree, int max_code) |
1398 | { | 1401 | { |
1399 | int n; /* iterates over all tree elements */ | 1402 | int n; /* iterates over all tree elements */ |
1400 | int prevlen = -1; /* last emitted length */ | 1403 | int prevlen = -1; /* last emitted length */ |
@@ -1446,7 +1449,7 @@ static void scan_tree(ct_data * tree, int max_code) | |||
1446 | * Send a literal or distance tree in compressed form, using the codes in | 1449 | * Send a literal or distance tree in compressed form, using the codes in |
1447 | * bl_tree. | 1450 | * bl_tree. |
1448 | */ | 1451 | */ |
1449 | static void send_tree(ct_data * tree, int max_code) | 1452 | static void send_tree(const ct_data *tree, int max_code) |
1450 | { | 1453 | { |
1451 | int n; /* iterates over all tree elements */ | 1454 | int n; /* iterates over all tree elements */ |
1452 | int prevlen = -1; /* last emitted length */ | 1455 | int prevlen = -1; /* last emitted length */ |
@@ -1622,7 +1625,7 @@ static int ct_tally(int dist, int lc) | |||
1622 | /* =========================================================================== | 1625 | /* =========================================================================== |
1623 | * Send the block data compressed using the given Huffman trees | 1626 | * Send the block data compressed using the given Huffman trees |
1624 | */ | 1627 | */ |
1625 | static void compress_block(ct_data * ltree, ct_data * dtree) | 1628 | static void compress_block(const ct_data *ltree, const ct_data *dtree) |
1626 | { | 1629 | { |
1627 | unsigned dist; /* distance of matched string */ | 1630 | unsigned dist; /* distance of matched string */ |
1628 | int lc; /* match length or unmatched char (if dist == 0) */ | 1631 | int lc; /* match length or unmatched char (if dist == 0) */ |
@@ -1672,7 +1675,7 @@ static void compress_block(ct_data * ltree, ct_data * dtree) | |||
1672 | * trees or store, and output the encoded block to the zip file. This function | 1675 | * trees or store, and output the encoded block to the zip file. This function |
1673 | * returns the total compressed length for the file so far. | 1676 | * returns the total compressed length for the file so far. |
1674 | */ | 1677 | */ |
1675 | static void flush_block(char *buf, ulg stored_len, int eof) | 1678 | static void flush_block(const char *buf, ulg stored_len, int eof) |
1676 | { | 1679 | { |
1677 | ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ | 1680 | ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ |
1678 | int max_blindex; /* index of last bit length code of non zero freq */ | 1681 | int max_blindex; /* index of last bit length code of non zero freq */ |
@@ -1919,7 +1922,7 @@ static void bi_init(void) | |||
1919 | /* =========================================================================== | 1922 | /* =========================================================================== |
1920 | * Initialize the "longest match" routines for a new file | 1923 | * Initialize the "longest match" routines for a new file |
1921 | */ | 1924 | */ |
1922 | static void lm_init(unsigned *flags16p) | 1925 | static void lm_init(void) |
1923 | { | 1926 | { |
1924 | unsigned j; | 1927 | unsigned j; |
1925 | 1928 | ||
@@ -1927,8 +1930,6 @@ static void lm_init(unsigned *flags16p) | |||
1927 | memset(head, 0, HASH_SIZE * sizeof(*head)); | 1930 | memset(head, 0, HASH_SIZE * sizeof(*head)); |
1928 | /* prev will be initialized on the fly */ | 1931 | /* prev will be initialized on the fly */ |
1929 | 1932 | ||
1930 | /* speed options for the general purpose bit flag */ | ||
1931 | *flags16p |= 2; /* FAST 4, SLOW 2 */ | ||
1932 | /* ??? reduce max_chain_length for binary files */ | 1933 | /* ??? reduce max_chain_length for binary files */ |
1933 | 1934 | ||
1934 | //G1.strstart = 0; // globals are zeroed in pack_gzip() | 1935 | //G1.strstart = 0; // globals are zeroed in pack_gzip() |
@@ -2076,10 +2077,16 @@ static void zip(void) | |||
2076 | 2077 | ||
2077 | bi_init(); | 2078 | bi_init(); |
2078 | ct_init(); | 2079 | ct_init(); |
2079 | deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */ | 2080 | lm_init(); |
2080 | lm_init(&deflate_flags); | ||
2081 | 2081 | ||
2082 | put_16bit(deflate_flags | 0x300); /* extra flags. OS id = 3 (Unix) */ | 2082 | deflate_flags = 0x300; /* extra flags. OS id = 3 (Unix) */ |
2083 | #if ENABLE_FEATURE_GZIP_LEVELS | ||
2084 | /* Note that comp_level < 4 do not exist in this version of gzip */ | ||
2085 | if (comp_level_minus4 == 9 - 4) { | ||
2086 | deflate_flags |= 0x02; /* SLOW flag */ | ||
2087 | } | ||
2088 | #endif | ||
2089 | put_16bit(deflate_flags); | ||
2083 | 2090 | ||
2084 | /* The above 32-bit misaligns outbuf (10 bytes are stored), flush it */ | 2091 | /* The above 32-bit misaligns outbuf (10 bytes are stored), flush it */ |
2085 | flush_outbuf_if_32bit_optimized(); | 2092 | flush_outbuf_if_32bit_optimized(); |
@@ -2222,8 +2229,11 @@ int gzip_main(int argc UNUSED_PARAM, char **argv) | |||
2222 | #if ENABLE_FEATURE_GZIP_LEVELS | 2229 | #if ENABLE_FEATURE_GZIP_LEVELS |
2223 | opt >>= (BBUNPK_OPTSTRLEN IF_FEATURE_GZIP_DECOMPRESS(+ 2) + 1); /* drop cfkvq[dt]n bits */ | 2230 | opt >>= (BBUNPK_OPTSTRLEN IF_FEATURE_GZIP_DECOMPRESS(+ 2) + 1); /* drop cfkvq[dt]n bits */ |
2224 | if (opt == 0) | 2231 | if (opt == 0) |
2225 | opt = 1 << 6; /* default: 6 */ | 2232 | opt = 1 << 5; /* default: 6 */ |
2226 | opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */ | 2233 | opt = ffs(opt >> 4); /* Maps -1..-4 to [0], -5 to [1] ... -9 to [5] */ |
2234 | |||
2235 | comp_level_minus4 = opt; | ||
2236 | |||
2227 | max_chain_length = 1 << gzip_level_config[opt].chain_shift; | 2237 | max_chain_length = 1 << gzip_level_config[opt].chain_shift; |
2228 | good_match = gzip_level_config[opt].good; | 2238 | good_match = gzip_level_config[opt].good; |
2229 | max_lazy_match = gzip_level_config[opt].lazy2 * 2; | 2239 | max_lazy_match = gzip_level_config[opt].lazy2 * 2; |
diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c index cf07f71df..c0332d414 100644 --- a/archival/libarchive/decompress_gunzip.c +++ b/archival/libarchive/decompress_gunzip.c | |||
@@ -39,7 +39,8 @@ typedef struct huft_t { | |||
39 | unsigned char e; /* number of extra bits or operation */ | 39 | unsigned char e; /* number of extra bits or operation */ |
40 | unsigned char b; /* number of bits in this code or subcode */ | 40 | unsigned char b; /* number of bits in this code or subcode */ |
41 | union { | 41 | union { |
42 | unsigned short n; /* literal, length base, or distance base */ | 42 | unsigned n; /* literal, length base, or distance base */ |
43 | /* ^^^^^ was "unsigned short", but that results in larger code */ | ||
43 | struct huft_t *t; /* pointer to next level of table */ | 44 | struct huft_t *t; /* pointer to next level of table */ |
44 | } v; | 45 | } v; |
45 | } huft_t; | 46 | } huft_t; |
@@ -184,29 +185,26 @@ static const uint16_t mask_bits[] ALIGN2 = { | |||
184 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff | 185 | 0x01ff, 0x03ff, 0x07ff, 0x0fff, 0x1fff, 0x3fff, 0x7fff, 0xffff |
185 | }; | 186 | }; |
186 | 187 | ||
187 | /* Copy lengths for literal codes 257..285 */ | 188 | /* Put lengths/offsets and extra bits in a struct of arrays |
188 | static const uint16_t cplens[] ALIGN2 = { | 189 | * to make calls to huft_build() have one fewer parameter. |
189 | 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, | 190 | */ |
190 | 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 | 191 | struct cp_ext { |
192 | uint16_t cp[31]; | ||
193 | uint8_t ext[31]; | ||
191 | }; | 194 | }; |
192 | 195 | /* Copy lengths and extra bits for literal codes 257..285 */ | |
193 | /* note: see note #13 above about the 258 in this list. */ | 196 | /* note: see note #13 above about the 258 in this list. */ |
194 | /* Extra bits for literal codes 257..285 */ | 197 | static const struct cp_ext lit = { |
195 | static const uint8_t cplext[] ALIGN1 = { | 198 | /*257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 */ |
196 | 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, | 199 | /*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 */ |
197 | 5, 5, 5, 0, 99, 99 | 200 | { 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 }, |
198 | }; /* 99 == invalid */ | 201 | { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 } /* 99 == invalid */ |
199 | |||
200 | /* Copy offsets for distance codes 0..29 */ | ||
201 | static const uint16_t cpdist[] ALIGN2 = { | ||
202 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, | ||
203 | 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 | ||
204 | }; | 202 | }; |
205 | 203 | /* Copy offsets and extra bits for distance codes 0..29 */ | |
206 | /* Extra bits for distance codes */ | 204 | static const struct cp_ext dist = { |
207 | static const uint8_t cpdext[] ALIGN1 = { | 205 | /*0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 */ |
208 | 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, | 206 | { 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577 }, |
209 | 11, 11, 12, 12, 13, 13 | 207 | { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 } |
210 | }; | 208 | }; |
211 | 209 | ||
212 | /* Tables for deflate from PKZIP's appnote.txt. */ | 210 | /* Tables for deflate from PKZIP's appnote.txt. */ |
@@ -277,22 +275,25 @@ static unsigned fill_bitbuffer(STATE_PARAM unsigned bitbuffer, unsigned *current | |||
277 | 275 | ||
278 | 276 | ||
279 | /* Given a list of code lengths and a maximum table size, make a set of | 277 | /* Given a list of code lengths and a maximum table size, make a set of |
280 | * tables to decode that set of codes. Return zero on success, one if | 278 | * tables to decode that set of codes. |
281 | * the given code set is incomplete (the tables are still built in this | ||
282 | * case), two if the input is invalid (an oversubscribed set of lengths) | ||
283 | * - in this case stores NULL in *t. | ||
284 | * | 279 | * |
285 | * b: code lengths in bits (all assumed <= BMAX) | 280 | * b: code lengths in bits (all assumed <= BMAX) |
286 | * n: number of codes (assumed <= N_MAX) | 281 | * n: number of codes (assumed <= N_MAX) |
287 | * s: number of simple-valued codes (0..s-1) | 282 | * s: number of simple-valued codes (0..s-1) |
288 | * d: list of base values for non-simple codes | 283 | * cp_ext->cp,ext: list of base values/extra bits for non-simple codes |
289 | * e: list of extra bits for non-simple codes | ||
290 | * t: result: starting table | ||
291 | * m: maximum lookup bits, returns actual | 284 | * m: maximum lookup bits, returns actual |
285 | * result: starting table | ||
286 | * | ||
287 | * On error, returns a value with lowest-bit set on error. | ||
288 | * It can be just the value of 0x1, | ||
289 | * or a valid pointer to a Huffman table, ORed with 0x1 if incompete table | ||
290 | * is given: "fixed inflate" decoder feeds us such data. | ||
292 | */ | 291 | */ |
293 | static int huft_build(const unsigned *b, const unsigned n, | 292 | #define BAD_HUFT(p) ((uintptr_t)(p) & 1) |
294 | const unsigned s, const unsigned short *d, | 293 | #define ERR_RET ((huft_t*)(uintptr_t)1) |
295 | const unsigned char *e, huft_t **t, unsigned *m) | 294 | static huft_t* huft_build(const unsigned *b, const unsigned n, |
295 | const unsigned s, const struct cp_ext *cp_ext, | ||
296 | unsigned *m) | ||
296 | { | 297 | { |
297 | unsigned a; /* counter for codes of length k */ | 298 | unsigned a; /* counter for codes of length k */ |
298 | unsigned c[BMAX + 1]; /* bit length count table */ | 299 | unsigned c[BMAX + 1]; /* bit length count table */ |
@@ -314,12 +315,12 @@ static int huft_build(const unsigned *b, const unsigned n, | |||
314 | unsigned *xp; /* pointer into x */ | 315 | unsigned *xp; /* pointer into x */ |
315 | int y; /* number of dummy codes added */ | 316 | int y; /* number of dummy codes added */ |
316 | unsigned z; /* number of entries in current table */ | 317 | unsigned z; /* number of entries in current table */ |
318 | huft_t *result; | ||
319 | huft_t **t; | ||
317 | 320 | ||
318 | /* Length of EOB code, if any */ | 321 | /* Length of EOB code, if any */ |
319 | eob_len = n > 256 ? b[256] : BMAX; | 322 | eob_len = n > 256 ? b[256] : BMAX; |
320 | 323 | ||
321 | *t = NULL; | ||
322 | |||
323 | /* Generate counts for each bit length */ | 324 | /* Generate counts for each bit length */ |
324 | memset(c, 0, sizeof(c)); | 325 | memset(c, 0, sizeof(c)); |
325 | p = b; | 326 | p = b; |
@@ -335,9 +336,8 @@ static int huft_build(const unsigned *b, const unsigned n, | |||
335 | q[1].b = 1; | 336 | q[1].b = 1; |
336 | q[2].e = 99; /* invalid code marker */ | 337 | q[2].e = 99; /* invalid code marker */ |
337 | q[2].b = 1; | 338 | q[2].b = 1; |
338 | *t = q + 1; | ||
339 | *m = 1; | 339 | *m = 1; |
340 | return 0; | 340 | return q + 1; |
341 | } | 341 | } |
342 | 342 | ||
343 | /* Find minimum and maximum length, bound *m by those */ | 343 | /* Find minimum and maximum length, bound *m by those */ |
@@ -353,11 +353,11 @@ static int huft_build(const unsigned *b, const unsigned n, | |||
353 | for (y = 1 << j; j < i; j++, y <<= 1) { | 353 | for (y = 1 << j; j < i; j++, y <<= 1) { |
354 | y -= c[j]; | 354 | y -= c[j]; |
355 | if (y < 0) | 355 | if (y < 0) |
356 | return 2; /* bad input: more codes than bits */ | 356 | return ERR_RET; /* bad input: more codes than bits */ |
357 | } | 357 | } |
358 | y -= c[i]; | 358 | y -= c[i]; |
359 | if (y < 0) | 359 | if (y < 0) |
360 | return 2; | 360 | return ERR_RET; |
361 | c[i] += y; | 361 | c[i] += y; |
362 | 362 | ||
363 | /* Generate starting offsets into the value table for each length */ | 363 | /* Generate starting offsets into the value table for each length */ |
@@ -384,6 +384,8 @@ static int huft_build(const unsigned *b, const unsigned n, | |||
384 | } while (++i < n); | 384 | } while (++i < n); |
385 | 385 | ||
386 | /* Generate the Huffman codes and for each, make the table entries */ | 386 | /* Generate the Huffman codes and for each, make the table entries */ |
387 | result = ERR_RET; | ||
388 | t = &result; | ||
387 | x[0] = i = 0; /* first Huffman code is zero */ | 389 | x[0] = i = 0; /* first Huffman code is zero */ |
388 | p = v; /* grab values in bit order */ | 390 | p = v; /* grab values in bit order */ |
389 | htl = -1; /* no tables yet--level -1 */ | 391 | htl = -1; /* no tables yet--level -1 */ |
@@ -449,8 +451,8 @@ static int huft_build(const unsigned *b, const unsigned n, | |||
449 | r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */ | 451 | r.e = (unsigned char) (*p < 256 ? 16 : 15); /* 256 is EOB code */ |
450 | r.v.n = (unsigned short) (*p++); /* simple code is just the value */ | 452 | r.v.n = (unsigned short) (*p++); /* simple code is just the value */ |
451 | } else { | 453 | } else { |
452 | r.e = (unsigned char) e[*p - s]; /* non-simple--look up in lists */ | 454 | r.e = (unsigned char) cp_ext->ext[*p - s]; /* non-simple--look up in lists */ |
453 | r.v.n = d[*p++ - s]; | 455 | r.v.n = cp_ext->cp[*p++ - s]; |
454 | } | 456 | } |
455 | 457 | ||
456 | /* fill code-like entries with r */ | 458 | /* fill code-like entries with r */ |
@@ -475,8 +477,11 @@ static int huft_build(const unsigned *b, const unsigned n, | |||
475 | /* return actual size of base table */ | 477 | /* return actual size of base table */ |
476 | *m = ws[1]; | 478 | *m = ws[1]; |
477 | 479 | ||
478 | /* Return 1 if we were given an incomplete table */ | 480 | if (y != 0 && g != 1) /* we were given an incomplete table */ |
479 | return y != 0 && g != 1; | 481 | /* return "result" ORed with 1 */ |
482 | return (void*)((uintptr_t)result | 1); | ||
483 | |||
484 | return result; | ||
480 | } | 485 | } |
481 | 486 | ||
482 | 487 | ||
@@ -777,14 +782,17 @@ static int inflate_block(STATE_PARAM smallint *e) | |||
777 | for (; i < 288; i++) /* make a complete, but wrong code set */ | 782 | for (; i < 288; i++) /* make a complete, but wrong code set */ |
778 | ll[i] = 8; | 783 | ll[i] = 8; |
779 | bl = 7; | 784 | bl = 7; |
780 | huft_build(ll, 288, 257, cplens, cplext, &inflate_codes_tl, &bl); | 785 | inflate_codes_tl = huft_build(ll, 288, 257, &lit, &bl); |
781 | /* huft_build() never return nonzero - we use known data */ | 786 | /* ^^^ never returns error here - we use known data */ |
782 | 787 | ||
783 | /* set up distance table */ | 788 | /* set up distance table */ |
784 | for (i = 0; i < 30; i++) /* make an incomplete code set */ | 789 | for (i = 0; i < 30; i++) /* make an incomplete code set */ |
785 | ll[i] = 5; | 790 | ll[i] = 5; |
786 | bd = 5; | 791 | bd = 5; |
787 | huft_build(ll, 30, 0, cpdist, cpdext, &inflate_codes_td, &bd); | 792 | inflate_codes_td = huft_build(ll, 30, 0, &dist, &bd); |
793 | /* ^^^ does return error here! (lsb bit is set) - we gave it incomplete code set */ | ||
794 | /* clearing error bit: */ | ||
795 | inflate_codes_td = (void*)((uintptr_t)inflate_codes_td & ~(uintptr_t)1); | ||
788 | 796 | ||
789 | /* set up data for inflate_codes() */ | 797 | /* set up data for inflate_codes() */ |
790 | inflate_codes_setup(PASS_STATE bl, bd); | 798 | inflate_codes_setup(PASS_STATE bl, bd); |
@@ -850,9 +858,9 @@ static int inflate_block(STATE_PARAM smallint *e) | |||
850 | 858 | ||
851 | /* build decoding table for trees - single level, 7 bit lookup */ | 859 | /* build decoding table for trees - single level, 7 bit lookup */ |
852 | bl = 7; | 860 | bl = 7; |
853 | i = huft_build(ll, 19, 19, NULL, NULL, &inflate_codes_tl, &bl); | 861 | inflate_codes_tl = huft_build(ll, 19, 19, NULL, &bl); |
854 | if (i != 0) { | 862 | if (BAD_HUFT(inflate_codes_tl)) { |
855 | abort_unzip(PASS_STATE_ONLY); //return i; /* incomplete code set */ | 863 | abort_unzip(PASS_STATE_ONLY); /* incomplete code set */ |
856 | } | 864 | } |
857 | 865 | ||
858 | /* read in literal and distance code lengths */ | 866 | /* read in literal and distance code lengths */ |
@@ -915,14 +923,13 @@ static int inflate_block(STATE_PARAM smallint *e) | |||
915 | 923 | ||
916 | /* build the decoding tables for literal/length and distance codes */ | 924 | /* build the decoding tables for literal/length and distance codes */ |
917 | bl = lbits; | 925 | bl = lbits; |
918 | 926 | inflate_codes_tl = huft_build(ll, nl, 257, &lit, &bl); | |
919 | i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl); | 927 | if (BAD_HUFT(inflate_codes_tl)) { |
920 | if (i != 0) { | ||
921 | abort_unzip(PASS_STATE_ONLY); | 928 | abort_unzip(PASS_STATE_ONLY); |
922 | } | 929 | } |
923 | bd = dbits; | 930 | bd = dbits; |
924 | i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd); | 931 | inflate_codes_td = huft_build(ll + nl, nd, 0, &dist, &bd); |
925 | if (i != 0) { | 932 | if (BAD_HUFT(inflate_codes_td)) { |
926 | abort_unzip(PASS_STATE_ONLY); | 933 | abort_unzip(PASS_STATE_ONLY); |
927 | } | 934 | } |
928 | 935 | ||
diff --git a/archival/libarchive/decompress_unxz.c b/archival/libarchive/decompress_unxz.c index f03341384..3dd9bbf49 100644 --- a/archival/libarchive/decompress_unxz.c +++ b/archival/libarchive/decompress_unxz.c | |||
@@ -96,6 +96,24 @@ unpack_xz_stream(transformer_state_t *xstate) | |||
96 | */ | 96 | */ |
97 | do { | 97 | do { |
98 | if (membuf[iobuf.in_pos] != 0) { | 98 | if (membuf[iobuf.in_pos] != 0) { |
99 | /* There is more data, but is it XZ data? | ||
100 | * Example: dpkg-deb -f busybox_1.30.1-4_amd64.deb | ||
101 | * reads control.tar.xz "control" file | ||
102 | * inside the ar archive, but tar.xz | ||
103 | * extraction code reaches end of xz data, | ||
104 | * reached this code and reads the beginning | ||
105 | * of data.tar.xz's ar header, which isn't xz data, | ||
106 | * and prints "corrupted data". | ||
107 | * The correct solution is to not read | ||
108 | * past nested archive (to simulate EOF). | ||
109 | * This is a workaround: | ||
110 | */ | ||
111 | if (membuf[iobuf.in_pos] != 0xfd) { | ||
112 | /* It's definitely not a xz signature | ||
113 | * (which is 0xfd,"7zXZ",0x00). | ||
114 | */ | ||
115 | goto end; | ||
116 | } | ||
99 | xz_dec_reset(state); | 117 | xz_dec_reset(state); |
100 | goto do_run; | 118 | goto do_run; |
101 | } | 119 | } |
@@ -128,7 +146,7 @@ unpack_xz_stream(transformer_state_t *xstate) | |||
128 | break; | 146 | break; |
129 | } | 147 | } |
130 | } | 148 | } |
131 | 149 | end: | |
132 | xz_dec_end(state); | 150 | xz_dec_end(state); |
133 | free(membuf); | 151 | free(membuf); |
134 | 152 | ||
diff --git a/archival/libarchive/unxz/xz_stream.h b/archival/libarchive/unxz/xz_stream.h index 66cb5a705..45056e42c 100644 --- a/archival/libarchive/unxz/xz_stream.h +++ b/archival/libarchive/unxz/xz_stream.h | |||
@@ -25,7 +25,7 @@ | |||
25 | 25 | ||
26 | #define STREAM_HEADER_SIZE 12 | 26 | #define STREAM_HEADER_SIZE 12 |
27 | 27 | ||
28 | #define HEADER_MAGIC "\3757zXZ" | 28 | #define HEADER_MAGIC "\375""7zXZ" |
29 | #define HEADER_MAGIC_SIZE 6 | 29 | #define HEADER_MAGIC_SIZE 6 |
30 | 30 | ||
31 | #define FOOTER_MAGIC "YZ" | 31 | #define FOOTER_MAGIC "YZ" |
diff --git a/archival/tar.c b/archival/tar.c index 6618c9ecc..c57bff779 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -1066,7 +1066,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv) | |||
1066 | IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive | 1066 | IF_FEATURE_TAR_CREATE("c--tx:t--cx:x--ct") // mutually exclusive |
1067 | IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive | 1067 | IF_NOT_FEATURE_TAR_CREATE("t--x:x--t") // mutually exclusive |
1068 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS | 1068 | #if ENABLE_FEATURE_TAR_LONG_OPTIONS |
1069 | ":\xf9+" // --strip-components=NUM | 1069 | ":\xf8+" // --strip-components=NUM |
1070 | #endif | 1070 | #endif |
1071 | LONGOPTS | 1071 | LONGOPTS |
1072 | , &base_dir // -C dir | 1072 | , &base_dir // -C dir |