aboutsummaryrefslogtreecommitdiff
path: root/archival/libarchive
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2014-01-02 10:25:11 +0000
committerRon Yorston <rmy@pobox.com>2014-01-02 10:25:11 +0000
commitb8f278ee745778806118f57fb7884d205eba05ad (patch)
treefef237f6dd302c59918cf389a60c120e58d3e086 /archival/libarchive
parent3fd34651ea72ea1c335d3170f234cb0517fd897f (diff)
parent57434022cefde87133b8ad39fb3b79c1274e7684 (diff)
downloadbusybox-w32-b8f278ee745778806118f57fb7884d205eba05ad.tar.gz
busybox-w32-b8f278ee745778806118f57fb7884d205eba05ad.tar.bz2
busybox-w32-b8f278ee745778806118f57fb7884d205eba05ad.zip
Merge branch 'busybox' into merge
Conflicts: archival/Config.src shell/ash.c
Diffstat (limited to 'archival/libarchive')
-rw-r--r--archival/libarchive/bz/compress.c16
-rw-r--r--archival/libarchive/decompress_bunzip2.c27
-rw-r--r--archival/libarchive/decompress_gunzip.c2
-rw-r--r--archival/libarchive/get_header_ar.c35
-rw-r--r--archival/libarchive/get_header_tar.c14
-rw-r--r--archival/libarchive/lzo1x_9x.c3
-rw-r--r--archival/libarchive/open_transformer.c5
7 files changed, 60 insertions, 42 deletions
diff --git a/archival/libarchive/bz/compress.c b/archival/libarchive/bz/compress.c
index e9f1afdaf..23de9d3f5 100644
--- a/archival/libarchive/bz/compress.c
+++ b/archival/libarchive/bz/compress.c
@@ -249,7 +249,7 @@ void generateMTFValues(EState* s)
249static NOINLINE 249static NOINLINE
250void sendMTFValues(EState* s) 250void sendMTFValues(EState* s)
251{ 251{
252 int32_t v, t, i, j, gs, ge, totc, bt, bc, iter; 252 int32_t v, t, i, j, gs, ge, bt, bc, iter;
253 int32_t nSelectors, alphaSize, minLen, maxLen, selCtr; 253 int32_t nSelectors, alphaSize, minLen, maxLen, selCtr;
254 int32_t nGroups; 254 int32_t nGroups;
255 255
@@ -345,7 +345,6 @@ void sendMTFValues(EState* s)
345 } 345 }
346#endif 346#endif
347 nSelectors = 0; 347 nSelectors = 0;
348 totc = 0;
349 gs = 0; 348 gs = 0;
350 while (1) { 349 while (1) {
351 /*--- Set group start & end marks. --*/ 350 /*--- Set group start & end marks. --*/
@@ -411,7 +410,6 @@ void sendMTFValues(EState* s)
411 bt = t; 410 bt = t;
412 } 411 }
413 } 412 }
414 totc += bc;
415 fave[bt]++; 413 fave[bt]++;
416 s->selector[nSelectors] = bt; 414 s->selector[nSelectors] = bt;
417 nSelectors++; 415 nSelectors++;
@@ -501,14 +499,14 @@ void sendMTFValues(EState* s)
501 for (i = 0; i < 16; i++) { 499 for (i = 0; i < 16; i++) {
502 if (sizeof(long) <= 4) { 500 if (sizeof(long) <= 4) {
503 inUse16 = inUse16*2 + 501 inUse16 = inUse16*2 +
504 ((*(uint32_t*)&(s->inUse[i * 16 + 0]) 502 ((*(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 0])
505 | *(uint32_t*)&(s->inUse[i * 16 + 4]) 503 | *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 4])
506 | *(uint32_t*)&(s->inUse[i * 16 + 8]) 504 | *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 8])
507 | *(uint32_t*)&(s->inUse[i * 16 + 12])) != 0); 505 | *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 12])) != 0);
508 } else { /* Our CPU can do better */ 506 } else { /* Our CPU can do better */
509 inUse16 = inUse16*2 + 507 inUse16 = inUse16*2 +
510 ((*(uint64_t*)&(s->inUse[i * 16 + 0]) 508 ((*(bb__aliased_uint64_t*)&(s->inUse[i * 16 + 0])
511 | *(uint64_t*)&(s->inUse[i * 16 + 8])) != 0); 509 | *(bb__aliased_uint64_t*)&(s->inUse[i * 16 + 8])) != 0);
512 } 510 }
513 } 511 }
514 512
diff --git a/archival/libarchive/decompress_bunzip2.c b/archival/libarchive/decompress_bunzip2.c
index dc252bb82..6396fe40d 100644
--- a/archival/libarchive/decompress_bunzip2.c
+++ b/archival/libarchive/decompress_bunzip2.c
@@ -42,6 +42,12 @@
42#include "libbb.h" 42#include "libbb.h"
43#include "bb_archive.h" 43#include "bb_archive.h"
44 44
45#if 0
46# define dbg(...) bb_error_msg(__VA_ARGS__)
47#else
48# define dbg(...) ((void)0)
49#endif
50
45/* Constants for Huffman coding */ 51/* Constants for Huffman coding */
46#define MAX_GROUPS 6 52#define MAX_GROUPS 6
47#define GROUP_SIZE 50 /* 64 would have been more efficient */ 53#define GROUP_SIZE 50 /* 64 would have been more efficient */
@@ -52,13 +58,13 @@
52 58
53/* Status return values */ 59/* Status return values */
54#define RETVAL_OK 0 60#define RETVAL_OK 0
55#define RETVAL_LAST_BLOCK (-1) 61#define RETVAL_LAST_BLOCK (dbg("%d", __LINE__), -1)
56#define RETVAL_NOT_BZIP_DATA (-2) 62#define RETVAL_NOT_BZIP_DATA (dbg("%d", __LINE__), -2)
57#define RETVAL_UNEXPECTED_INPUT_EOF (-3) 63#define RETVAL_UNEXPECTED_INPUT_EOF (dbg("%d", __LINE__), -3)
58#define RETVAL_SHORT_WRITE (-4) 64#define RETVAL_SHORT_WRITE (dbg("%d", __LINE__), -4)
59#define RETVAL_DATA_ERROR (-5) 65#define RETVAL_DATA_ERROR (dbg("%d", __LINE__), -5)
60#define RETVAL_OUT_OF_MEMORY (-6) 66#define RETVAL_OUT_OF_MEMORY (dbg("%d", __LINE__), -6)
61#define RETVAL_OBSOLETE_INPUT (-7) 67#define RETVAL_OBSOLETE_INPUT (dbg("%d", __LINE__), -7)
62 68
63/* Other housekeeping constants */ 69/* Other housekeeping constants */
64#define IOBUF_SIZE 4096 70#define IOBUF_SIZE 4096
@@ -440,7 +446,11 @@ static int get_next_block(bunzip_data *bd)
440 literal used is the one at the head of the mtfSymbol array.) */ 446 literal used is the one at the head of the mtfSymbol array.) */
441 if (runPos != 0) { 447 if (runPos != 0) {
442 uint8_t tmp_byte; 448 uint8_t tmp_byte;
443 if (dbufCount + runCnt >= dbufSize) return RETVAL_DATA_ERROR; 449 if (dbufCount + runCnt > dbufSize) {
450 dbg("dbufCount:%d+runCnt:%d %d > dbufSize:%d RETVAL_DATA_ERROR",
451 dbufCount, runCnt, dbufCount + runCnt, dbufSize);
452 return RETVAL_DATA_ERROR;
453 }
444 tmp_byte = symToByte[mtfSymbol[0]]; 454 tmp_byte = symToByte[mtfSymbol[0]];
445 byteCount[tmp_byte] += runCnt; 455 byteCount[tmp_byte] += runCnt;
446 while (--runCnt >= 0) dbuf[dbufCount++] = (uint32_t)tmp_byte; 456 while (--runCnt >= 0) dbuf[dbufCount++] = (uint32_t)tmp_byte;
@@ -808,7 +818,6 @@ static char *const bunzip_errors[] = {
808/* Dumb little test thing, decompress stdin to stdout */ 818/* Dumb little test thing, decompress stdin to stdout */
809int main(int argc, char **argv) 819int main(int argc, char **argv)
810{ 820{
811 int i;
812 char c; 821 char c;
813 822
814 int i = unpack_bz2_stream(0, 1); 823 int i = unpack_bz2_stream(0, 1);
diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c
index 4e6b138c3..7c6f38ec3 100644
--- a/archival/libarchive/decompress_gunzip.c
+++ b/archival/libarchive/decompress_gunzip.c
@@ -336,7 +336,7 @@ static int huft_build(const unsigned *b, const unsigned n,
336 } 336 }
337 337
338 /* Find minimum and maximum length, bound *m by those */ 338 /* Find minimum and maximum length, bound *m by those */
339 for (j = 1; (c[j] == 0) && (j <= BMAX); j++) 339 for (j = 1; (j <= BMAX) && (c[j] == 0); j++)
340 continue; 340 continue;
341 k = j; /* minimum code length */ 341 k = j; /* minimum code length */
342 for (i = BMAX; (c[i] == 0) && i; i--) 342 for (i = BMAX; (c[i] == 0) && i; i--)
diff --git a/archival/libarchive/get_header_ar.c b/archival/libarchive/get_header_ar.c
index 23c412496..c66bb3ee7 100644
--- a/archival/libarchive/get_header_ar.c
+++ b/archival/libarchive/get_header_ar.c
@@ -8,11 +8,19 @@
8#include "bb_archive.h" 8#include "bb_archive.h"
9#include "ar.h" 9#include "ar.h"
10 10
11static unsigned read_num(const char *str, int base) 11/* WARNING: Clobbers str[len], so fields must be read in reverse order! */
12static unsigned read_num(char *str, int base, int len)
12{ 13{
14 int err;
15
16 /* ar fields are fixed length text strings (padded with spaces).
17 * Ensure bb_strtou doesn't read past the field in case the full
18 * width is used. */
19 str[len] = 0;
20
13 /* This code works because 21 /* This code works because
14 * on misformatted numbers bb_strtou returns all-ones */ 22 * on misformatted numbers bb_strtou returns all-ones */
15 int err = bb_strtou(str, NULL, base); 23 err = bb_strtou(str, NULL, base);
16 if (err == -1) 24 if (err == -1)
17 bb_error_msg_and_die("invalid ar header"); 25 bb_error_msg_and_die("invalid ar header");
18 return err; 26 return err;
@@ -51,11 +59,13 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
51 if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n') 59 if (ar.formatted.magic[0] != '`' || ar.formatted.magic[1] != '\n')
52 bb_error_msg_and_die("invalid ar header"); 60 bb_error_msg_and_die("invalid ar header");
53 61
54 /* FIXME: more thorough routine would be in order here 62 /*
55 * (we have something like that in tar) 63 * Note that the fields MUST be read in reverse order as
56 * but for now we are lax. */ 64 * read_num() clobbers the next byte after the field!
57 ar.formatted.magic[0] = '\0'; /* else 4G-2 file will have size="4294967294`\n..." */ 65 * Order is: name, date, uid, gid, mode, size, magic.
58 typed->size = size = read_num(ar.formatted.size, 10); 66 */
67 typed->size = size = read_num(ar.formatted.size, 10,
68 sizeof(ar.formatted.size));
59 69
60 /* special filenames have '/' as the first character */ 70 /* special filenames have '/' as the first character */
61 if (ar.formatted.name[0] == '/') { 71 if (ar.formatted.name[0] == '/') {
@@ -87,10 +97,10 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
87 * long filename pseudo file. Thus we decode the rest 97 * long filename pseudo file. Thus we decode the rest
88 * after dealing with long filename pseudo file. 98 * after dealing with long filename pseudo file.
89 */ 99 */
90 typed->mode = read_num(ar.formatted.mode, 8); 100 typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode));
91 typed->mtime = read_num(ar.formatted.date, 10); 101 typed->gid = read_num(ar.formatted.gid, 10, sizeof(ar.formatted.gid));
92 typed->uid = read_num(ar.formatted.uid, 10); 102 typed->uid = read_num(ar.formatted.uid, 10, sizeof(ar.formatted.uid));
93 typed->gid = read_num(ar.formatted.gid, 10); 103 typed->mtime = read_num(ar.formatted.date, 10, sizeof(ar.formatted.date));
94 104
95#if ENABLE_FEATURE_AR_LONG_FILENAMES 105#if ENABLE_FEATURE_AR_LONG_FILENAMES
96 if (ar.formatted.name[0] == '/') { 106 if (ar.formatted.name[0] == '/') {
@@ -98,7 +108,8 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle)
98 108
99 /* The number after the '/' indicates the offset in the ar data section 109 /* The number after the '/' indicates the offset in the ar data section
100 * (saved in ar_long_names) that conatains the real filename */ 110 * (saved in ar_long_names) that conatains the real filename */
101 long_offset = read_num(&ar.formatted.name[1], 10); 111 long_offset = read_num(&ar.formatted.name[1], 10,
112 sizeof(ar.formatted.name) - 1);
102 if (long_offset >= ar_long_name_size) { 113 if (long_offset >= ar_long_name_size) {
103 bb_error_msg_and_die("can't resolve long filename"); 114 bb_error_msg_and_die("can't resolve long filename");
104 } 115 }
diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c
index bc09756ba..32f842095 100644
--- a/archival/libarchive/get_header_tar.c
+++ b/archival/libarchive/get_header_tar.c
@@ -198,13 +198,13 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
198 * the message and we don't check whether we indeed 198 * the message and we don't check whether we indeed
199 * saw zero block directly before this. */ 199 * saw zero block directly before this. */
200 if (i == 0) { 200 if (i == 0) {
201 xfunc_error_retval = 0; 201 bb_error_msg("short read");
202 short_read: 202 /* this merely signals end of archive, not exit(1): */
203 bb_error_msg_and_die("short read"); 203 return EXIT_FAILURE;
204 } 204 }
205 if (i != 512) { 205 if (i != 512) {
206 IF_FEATURE_TAR_AUTODETECT(goto autodetect;) 206 IF_FEATURE_TAR_AUTODETECT(goto autodetect;)
207 goto short_read; 207 bb_error_msg_and_die("short read");
208 } 208 }
209 209
210#else 210#else
@@ -221,10 +221,10 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
221 */ 221 */
222 while (full_read(archive_handle->src_fd, &tar, 512) == 512) 222 while (full_read(archive_handle->src_fd, &tar, 512) == 512)
223 continue; 223 continue;
224 return EXIT_FAILURE; 224 return EXIT_FAILURE; /* "end of archive" */
225 } 225 }
226 archive_handle->tar__end = 1; 226 archive_handle->tar__end = 1;
227 return EXIT_SUCCESS; 227 return EXIT_SUCCESS; /* "decoded one header" */
228 } 228 }
229 archive_handle->tar__end = 0; 229 archive_handle->tar__end = 0;
230 230
@@ -471,5 +471,5 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
471 free(file_header->tar__uname); 471 free(file_header->tar__uname);
472 free(file_header->tar__gname); 472 free(file_header->tar__gname);
473#endif 473#endif
474 return EXIT_SUCCESS; 474 return EXIT_SUCCESS; /* "decoded one header" */
475} 475}
diff --git a/archival/libarchive/lzo1x_9x.c b/archival/libarchive/lzo1x_9x.c
index 897132987..2b490ae83 100644
--- a/archival/libarchive/lzo1x_9x.c
+++ b/archival/libarchive/lzo1x_9x.c
@@ -94,7 +94,7 @@ typedef struct {
94 ( ((0x9f5f * ((((b[p]<<5)^b[p+1])<<5) ^ b[p+2])) >> 5) & (SWD_HSIZE-1) ) 94 ( ((0x9f5f * ((((b[p]<<5)^b[p+1])<<5) ^ b[p+2])) >> 5) & (SWD_HSIZE-1) )
95 95
96#if defined(LZO_UNALIGNED_OK_2) 96#if defined(LZO_UNALIGNED_OK_2)
97# define HEAD2(b,p) (* (uint16_t *) &(b[p])) 97# define HEAD2(b,p) (* (bb__aliased_uint16_t *) &(b[p]))
98#else 98#else
99# define HEAD2(b,p) (b[p] ^ ((unsigned)b[p+1]<<8)) 99# define HEAD2(b,p) (b[p] ^ ((unsigned)b[p+1]<<8))
100#endif 100#endif
@@ -466,7 +466,6 @@ static int find_match(lzo1x_999_t *c, lzo_swd_p s,
466 } 466 }
467 467
468 s->m_len = 1; 468 s->m_len = 1;
469 s->m_len = 1;
470#ifdef SWD_BEST_OFF 469#ifdef SWD_BEST_OFF
471 if (s->use_best_off) 470 if (s->use_best_off)
472 memset(s->best_pos, 0, sizeof(s->best_pos)); 471 memset(s->best_pos, 0, sizeof(s->best_pos));
diff --git a/archival/libarchive/open_transformer.c b/archival/libarchive/open_transformer.c
index 841e9dce9..c4e02f0f7 100644
--- a/archival/libarchive/open_transformer.c
+++ b/archival/libarchive/open_transformer.c
@@ -81,16 +81,17 @@ void FAST_FUNC open_transformer(int fd, const char *transform_prog)
81 // FIXME: error check? 81 // FIXME: error check?
82#if BB_MMU 82#if BB_MMU
83 { 83 {
84 IF_DESKTOP(long long) int r;
84 transformer_aux_data_t aux; 85 transformer_aux_data_t aux;
85 init_transformer_aux_data(&aux); 86 init_transformer_aux_data(&aux);
86 aux.check_signature = check_signature; 87 aux.check_signature = check_signature;
87 transformer(&aux, fd, fd_pipe.wr); 88 r = transformer(&aux, fd, fd_pipe.wr);
88 if (ENABLE_FEATURE_CLEAN_UP) { 89 if (ENABLE_FEATURE_CLEAN_UP) {
89 close(fd_pipe.wr); /* send EOF */ 90 close(fd_pipe.wr); /* send EOF */
90 close(fd); 91 close(fd);
91 } 92 }
92 /* must be _exit! bug was actually seen here */ 93 /* must be _exit! bug was actually seen here */
93 _exit(EXIT_SUCCESS); 94 _exit(/*error if:*/ r < 0);
94 } 95 }
95#else 96#else
96 { 97 {