aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
Diffstat (limited to 'archival')
-rw-r--r--archival/bbunzip.c5
-rw-r--r--archival/libarchive/decompress_unlzma.c23
-rw-r--r--archival/libarchive/get_header_tar.c2
-rw-r--r--archival/libarchive/open_transformer.c10
-rw-r--r--archival/rpm.c2
-rw-r--r--archival/rpm2cpio.c2
-rw-r--r--archival/tar.c2
7 files changed, 28 insertions, 18 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index 3de8e1d48..4d417f3f1 100644
--- a/archival/bbunzip.c
+++ b/archival/bbunzip.c
@@ -72,7 +72,8 @@ int FAST_FUNC bbunpack(char **argv,
72 goto err; 72 goto err;
73 } else { 73 } else {
74 /* "clever zcat" with FILE */ 74 /* "clever zcat" with FILE */
75 int fd = open_zipped(filename); 75 /* fail_if_not_compressed because zcat refuses uncompressed input */
76 int fd = open_zipped(filename, /*fail_if_not_compressed:*/ 1);
76 if (fd < 0) 77 if (fd < 0)
77 goto err_name; 78 goto err_name;
78 xmove_fd(fd, STDIN_FILENO); 79 xmove_fd(fd, STDIN_FILENO);
@@ -80,7 +81,7 @@ int FAST_FUNC bbunpack(char **argv,
80 } else 81 } else
81 if (option_mask32 & SEAMLESS_MAGIC) { 82 if (option_mask32 & SEAMLESS_MAGIC) {
82 /* "clever zcat" on stdin */ 83 /* "clever zcat" on stdin */
83 if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_detected*/ 0)) 84 if (setup_unzip_on_fd(STDIN_FILENO, /*fail_if_not_compressed*/ 1))
84 goto err; 85 goto err;
85 } 86 }
86 87
diff --git a/archival/libarchive/decompress_unlzma.c b/archival/libarchive/decompress_unlzma.c
index ca32bd82c..3d99e1388 100644
--- a/archival/libarchive/decompress_unlzma.c
+++ b/archival/libarchive/decompress_unlzma.c
@@ -214,8 +214,6 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
214 uint32_t pos_state_mask; 214 uint32_t pos_state_mask;
215 uint32_t literal_pos_mask; 215 uint32_t literal_pos_mask;
216 uint16_t *p; 216 uint16_t *p;
217 int num_bits;
218 int num_probs;
219 rc_t *rc; 217 rc_t *rc;
220 int i; 218 int i;
221 uint8_t *buffer; 219 uint8_t *buffer;
@@ -239,6 +237,9 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
239 pos_state_mask = (1 << pb) - 1; 237 pos_state_mask = (1 << pb) - 1;
240 literal_pos_mask = (1 << lp) - 1; 238 literal_pos_mask = (1 << lp) - 1;
241 239
240 /* Example values from linux-3.3.4.tar.lzma:
241 * dict_size: 64M, dst_size: 2^64-1
242 */
242 header.dict_size = SWAP_LE32(header.dict_size); 243 header.dict_size = SWAP_LE32(header.dict_size);
243 header.dst_size = SWAP_LE64(header.dst_size); 244 header.dst_size = SWAP_LE64(header.dst_size);
244 245
@@ -247,11 +248,15 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
247 248
248 buffer = xmalloc(MIN(header.dst_size, header.dict_size)); 249 buffer = xmalloc(MIN(header.dst_size, header.dict_size));
249 250
250 num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)); 251 {
251 p = xmalloc(num_probs * sizeof(*p)); 252 int num_probs;
252 num_probs += LZMA_LITERAL - LZMA_BASE_SIZE; 253
253 for (i = 0; i < num_probs; i++) 254 num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
254 p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1; 255 p = xmalloc(num_probs * sizeof(*p));
256 num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
257 for (i = 0; i < num_probs; i++)
258 p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
259 }
255 260
256 rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */ 261 rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */
257 262
@@ -310,6 +315,7 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
310 goto one_byte2; 315 goto one_byte2;
311#endif 316#endif
312 } else { 317 } else {
318 int num_bits;
313 int offset; 319 int offset;
314 uint16_t *prob2; 320 uint16_t *prob2;
315#define prob_len prob2 321#define prob_len prob2
@@ -440,6 +446,9 @@ unpack_lzma_stream(transformer_aux_data_t *aux UNUSED_PARAM, int src_fd, int dst
440 } 446 }
441 len--; 447 len--;
442 } while (len != 0 && buffer_pos < header.dst_size); 448 } while (len != 0 && buffer_pos < header.dst_size);
449 /* FIXME: ...........^^^^^
450 * shouldn't it be "global_pos + buffer_pos < header.dst_size"?
451 */
443 } 452 }
444 } 453 }
445 454
diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c
index 54d910431..ba43bb073 100644
--- a/archival/libarchive/get_header_tar.c
+++ b/archival/libarchive/get_header_tar.c
@@ -243,7 +243,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
243 * or not first block (false positive, it's not .gz/.bz2!) */ 243 * or not first block (false positive, it's not .gz/.bz2!) */
244 if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0) 244 if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0)
245 goto err; 245 goto err;
246 if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 0) != 0) 246 if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 0) != 0)
247 err: 247 err:
248 bb_error_msg_and_die("invalid tar magic"); 248 bb_error_msg_and_die("invalid tar magic");
249 archive_handle->offset = 0; 249 archive_handle->offset = 0;
diff --git a/archival/libarchive/open_transformer.c b/archival/libarchive/open_transformer.c
index b11bf46af..e49eab409 100644
--- a/archival/libarchive/open_transformer.c
+++ b/archival/libarchive/open_transformer.c
@@ -120,7 +120,7 @@ void FAST_FUNC open_transformer(int fd, const char *transform_prog)
120/* Used by e.g. rpm which gives us a fd without filename, 120/* Used by e.g. rpm which gives us a fd without filename,
121 * thus we can't guess the format from filename's extension. 121 * thus we can't guess the format from filename's extension.
122 */ 122 */
123int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected) 123int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed)
124{ 124{
125 union { 125 union {
126 uint8_t b[4]; 126 uint8_t b[4];
@@ -161,7 +161,7 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
161 } 161 }
162 162
163 /* No known magic seen */ 163 /* No known magic seen */
164 if (fail_if_not_detected) 164 if (fail_if_not_compressed)
165 bb_error_msg_and_die("no gzip" 165 bb_error_msg_and_die("no gzip"
166 IF_FEATURE_SEAMLESS_BZ2("/bzip2") 166 IF_FEATURE_SEAMLESS_BZ2("/bzip2")
167 IF_FEATURE_SEAMLESS_XZ("/xz") 167 IF_FEATURE_SEAMLESS_XZ("/xz")
@@ -182,7 +182,7 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
182 return 0; 182 return 0;
183} 183}
184 184
185int FAST_FUNC open_zipped(const char *fname) 185int FAST_FUNC open_zipped(const char *fname, int fail_if_not_compressed)
186{ 186{
187 int fd; 187 int fd;
188 188
@@ -202,7 +202,7 @@ int FAST_FUNC open_zipped(const char *fname)
202 || (ENABLE_FEATURE_SEAMLESS_BZ2) 202 || (ENABLE_FEATURE_SEAMLESS_BZ2)
203 || (ENABLE_FEATURE_SEAMLESS_XZ) 203 || (ENABLE_FEATURE_SEAMLESS_XZ)
204 ) { 204 ) {
205 setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1); 205 setup_unzip_on_fd(fd, fail_if_not_compressed);
206 } 206 }
207 207
208 return fd; 208 return fd;
@@ -215,7 +215,7 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
215 int fd; 215 int fd;
216 char *image; 216 char *image;
217 217
218 fd = open_zipped(fname); 218 fd = open_zipped(fname, /*fail_if_not_compressed:*/ 0);
219 if (fd < 0) 219 if (fd < 0)
220 return NULL; 220 return NULL;
221 221
diff --git a/archival/rpm.c b/archival/rpm.c
index 885eddd64..105394481 100644
--- a/archival/rpm.c
+++ b/archival/rpm.c
@@ -122,7 +122,7 @@ static void extract_cpio(int fd, const char *source_rpm)
122 archive_handle->src_fd = fd; 122 archive_handle->src_fd = fd;
123 /*archive_handle->offset = 0; - init_handle() did it */ 123 /*archive_handle->offset = 0; - init_handle() did it */
124 124
125 setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_detected:*/ 1); 125 setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 1);
126 while (get_header_cpio(archive_handle) == EXIT_SUCCESS) 126 while (get_header_cpio(archive_handle) == EXIT_SUCCESS)
127 continue; 127 continue;
128} 128}
diff --git a/archival/rpm2cpio.c b/archival/rpm2cpio.c
index 61adde795..7057570f5 100644
--- a/archival/rpm2cpio.c
+++ b/archival/rpm2cpio.c
@@ -80,7 +80,7 @@ int rpm2cpio_main(int argc UNUSED_PARAM, char **argv)
80 // signal(SIGCHLD, check_errors_in_children); 80 // signal(SIGCHLD, check_errors_in_children);
81 81
82 /* This works, but doesn't report uncompress errors (they happen in child) */ 82 /* This works, but doesn't report uncompress errors (they happen in child) */
83 setup_unzip_on_fd(rpm_fd, /*fail_if_not_detected:*/ 1); 83 setup_unzip_on_fd(rpm_fd, /*fail_if_not_compressed:*/ 1);
84 if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0) 84 if (bb_copyfd_eof(rpm_fd, STDOUT_FILENO) < 0)
85 bb_error_msg_and_die("error unpacking"); 85 bb_error_msg_and_die("error unpacking");
86 86
diff --git a/archival/tar.c b/archival/tar.c
index d7938c09e..f2e4bedbe 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -1143,7 +1143,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1143 && flags == O_RDONLY 1143 && flags == O_RDONLY
1144 && !(opt & OPT_ANY_COMPRESS) 1144 && !(opt & OPT_ANY_COMPRESS)
1145 ) { 1145 ) {
1146 tar_handle->src_fd = open_zipped(tar_filename); 1146 tar_handle->src_fd = open_zipped(tar_filename, /*fail_if_not_compressed:*/ 0);
1147 if (tar_handle->src_fd < 0) 1147 if (tar_handle->src_fd < 0)
1148 bb_perror_msg_and_die("can't open '%s'", tar_filename); 1148 bb_perror_msg_and_die("can't open '%s'", tar_filename);
1149 } else { 1149 } else {