Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/archival/libarchive
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 3 added
- 1 deleted
- 27 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/archival/libarchive/Kbuild.src
r3232 r3621 5 5 # Licensed under GPLv2 or later, see file LICENSE in this source tree. 6 6 7 lib-y:= 7 lib-y:= common.o 8 8 9 9 COMMON_FILES:= \ … … 31 31 unpack_ar_archive.o \ 32 32 filter_accept_list_reassign.o \ 33 unsafe_prefix.o \ 33 34 get_header_ar.o \ 34 35 get_header_tar.o \ … … 36 37 get_header_tar_bz2.o \ 37 38 get_header_tar_lzma.o \ 39 get_header_tar_xz.o \ 38 40 39 41 INSERT 40 42 41 lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o42 lib-$(CONFIG_BUNZIP2) += decompress_bunzip2.o43 lib-$(CONFIG_UNLZMA) += decompress_unlzma.o44 lib-$(CONFIG_UNXZ) += decompress_unxz.o45 lib-$(CONFIG_CPIO) += get_header_cpio.o46 43 lib-$(CONFIG_DPKG) += $(DPKG_FILES) 47 44 lib-$(CONFIG_DPKG_DEB) += $(DPKG_FILES) 48 lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o 49 lib-$(CONFIG_RPM2CPIO) += decompress_gunzip.o get_header_cpio.o 50 lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o 51 lib-$(CONFIG_TAR) += get_header_tar.o 52 lib-$(CONFIG_UNCOMPRESS) += decompress_uncompress.o 53 lib-$(CONFIG_UNZIP) += decompress_gunzip.o 45 46 lib-$(CONFIG_AR) += get_header_ar.o unpack_ar_archive.o 47 lib-$(CONFIG_CPIO) += get_header_cpio.o 48 lib-$(CONFIG_TAR) += get_header_tar.o unsafe_prefix.o 49 lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o 54 50 lib-$(CONFIG_LZOP) += lzo1x_1.o lzo1x_1o.o lzo1x_d.o 55 51 lib-$(CONFIG_LZOP_COMPR_HIGH) += lzo1x_9x.o 52 lib-$(CONFIG_BUNZIP2) += open_transformer.o decompress_bunzip2.o 53 lib-$(CONFIG_UNLZMA) += open_transformer.o decompress_unlzma.o 54 lib-$(CONFIG_UNXZ) += open_transformer.o decompress_unxz.o 55 lib-$(CONFIG_GUNZIP) += open_transformer.o decompress_gunzip.o 56 lib-$(CONFIG_UNCOMPRESS) += open_transformer.o decompress_uncompress.o 57 lib-$(CONFIG_UNZIP) += open_transformer.o decompress_gunzip.o unsafe_prefix.o 58 lib-$(CONFIG_RPM2CPIO) += open_transformer.o decompress_gunzip.o get_header_cpio.o 59 lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o 60 61 lib-$(CONFIG_GZIP) += open_transformer.o 62 lib-$(CONFIG_BZIP2) += open_transformer.o 63 lib-$(CONFIG_LZOP) += open_transformer.o 64 lib-$(CONFIG_MAN) += open_transformer.o 65 lib-$(CONFIG_SETFONT) += open_transformer.o 66 lib-$(CONFIG_FEATURE_2_4_MODULES) += open_transformer.o 56 67 lib-$(CONFIG_MODINFO) += open_transformer.o 57 68 lib-$(CONFIG_INSMOD) += open_transformer.o 69 lib-$(CONFIG_DEPMOD) += open_transformer.o 70 lib-$(CONFIG_RMMOD) += open_transformer.o 71 lib-$(CONFIG_LSMOD) += open_transformer.o 72 lib-$(CONFIG_MODPROBE) += open_transformer.o 73 lib-$(CONFIG_MODPROBE_SMALL) += open_transformer.o 74 58 75 lib-$(CONFIG_FEATURE_SEAMLESS_Z) += open_transformer.o decompress_uncompress.o 59 76 lib-$(CONFIG_FEATURE_SEAMLESS_GZ) += open_transformer.o decompress_gunzip.o … … 62 79 lib-$(CONFIG_FEATURE_SEAMLESS_XZ) += open_transformer.o decompress_unxz.o 63 80 lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += open_transformer.o decompress_bunzip2.o 64 lib-$(CONFIG_FEATURE_COMPRESS_BBCONFIG) += decompress_bunzip2.o 65 lib-$(CONFIG_FEATURE_TAR_TO_COMMAND) += data_extract_to_command.o 81 lib-$(CONFIG_FEATURE_COMPRESS_BBCONFIG) += open_transformer.o decompress_bunzip2.o 66 82 67 83 ifneq ($(lib-y),) -
branches/3.3/mindi-busybox/archival/libarchive/bz/compress.c
r3232 r3621 250 250 void 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 253 int32_t nSelectors, alphaSize, minLen, maxLen, selCtr; 254 254 int32_t nGroups; … … 346 346 #endif 347 347 nSelectors = 0; 348 totc = 0;349 348 gs = 0; 350 349 while (1) { … … 387 386 cost[2] = cost23 & 0xffff; cost[3] = cost23 >> 16; 388 387 cost[4] = cost45 & 0xffff; cost[5] = cost45 >> 16; 389 390 388 } else 391 389 #endif … … 412 410 } 413 411 } 414 totc += bc;415 412 fave[bt]++; 416 413 s->selector[nSelectors] = bt; … … 502 499 if (sizeof(long) <= 4) { 503 500 inUse16 = inUse16*2 + 504 ((*( uint32_t*)&(s->inUse[i * 16 + 0])505 | *( uint32_t*)&(s->inUse[i * 16 + 4])506 | *( uint32_t*)&(s->inUse[i * 16 + 8])507 | *( uint32_t*)&(s->inUse[i * 16 + 12])) != 0);501 ((*(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 0]) 502 | *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 4]) 503 | *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 8]) 504 | *(bb__aliased_uint32_t*)&(s->inUse[i * 16 + 12])) != 0); 508 505 } else { /* Our CPU can do better */ 509 506 inUse16 = inUse16*2 + 510 ((*( uint64_t*)&(s->inUse[i * 16 + 0])511 | *( uint64_t*)&(s->inUse[i * 16 + 8])) != 0);507 ((*(bb__aliased_uint64_t*)&(s->inUse[i * 16 + 0]) 508 | *(bb__aliased_uint64_t*)&(s->inUse[i * 16 + 8])) != 0); 512 509 } 513 510 } -
branches/3.3/mindi-busybox/archival/libarchive/data_extract_all.c
r3232 r3621 12 12 int dst_fd; 13 13 int res; 14 char *hard_link; 15 #if ENABLE_FEATURE_TAR_LONG_OPTIONS 16 char *dst_name; 17 #else 18 # define dst_name (file_header->name) 19 #endif 14 20 15 21 #if ENABLE_FEATURE_TAR_SELINUX … … 24 30 #endif 25 31 32 /* Hard links are encoded as regular files of size 0 33 * with a nonempty link field */ 34 hard_link = NULL; 35 if (S_ISREG(file_header->mode) && file_header->size == 0) 36 hard_link = file_header->link_target; 37 38 #if ENABLE_FEATURE_TAR_LONG_OPTIONS 39 dst_name = file_header->name; 40 if (archive_handle->tar__strip_components) { 41 unsigned n = archive_handle->tar__strip_components; 42 do { 43 dst_name = strchr(dst_name, '/'); 44 if (!dst_name || dst_name[1] == '\0') { 45 data_skip(archive_handle); 46 goto ret; 47 } 48 dst_name++; 49 /* 50 * Link target is shortened only for hardlinks: 51 * softlinks restored unchanged. 52 */ 53 if (hard_link) { 54 // GNU tar 1.26 does not check that we reached end of link name: 55 // if "dir/hardlink" is hardlinked to "file", 56 // tar xvf a.tar --strip-components=1 says: 57 // tar: hardlink: Cannot hard link to '': No such file or directory 58 // and continues processing. We silently skip such entries. 59 hard_link = strchr(hard_link, '/'); 60 if (!hard_link || hard_link[1] == '\0') { 61 data_skip(archive_handle); 62 goto ret; 63 } 64 hard_link++; 65 } 66 } while (--n != 0); 67 } 68 #endif 69 26 70 if (archive_handle->ah_flags & ARCHIVE_CREATE_LEADING_DIRS) { 27 char *slash = strrchr( file_header->name, '/');71 char *slash = strrchr(dst_name, '/'); 28 72 if (slash) { 29 73 *slash = '\0'; 30 bb_make_directory( file_header->name, -1, FILEUTILS_RECUR);74 bb_make_directory(dst_name, -1, FILEUTILS_RECUR); 31 75 *slash = '/'; 32 76 } … … 36 80 /* Remove the entry if it exists */ 37 81 if (!S_ISDIR(file_header->mode)) { 38 /* Is it hardlink? 39 * We encode hard links as regular files of size 0 with a symlink */ 40 if (S_ISREG(file_header->mode) 41 && file_header->link_target 42 && file_header->size == 0 43 ) { 82 if (hard_link) { 44 83 /* Ugly special case: 45 84 * tar cf t.tar hardlink1 hardlink2 hardlink1 … … 49 88 * hardlink1 -> hardlink1 <== !!! 50 89 */ 51 if (strcmp( file_header->link_target, file_header->name) == 0)90 if (strcmp(hard_link, dst_name) == 0) 52 91 goto ret; 53 92 } 54 93 /* Proceed with deleting */ 55 if (unlink( file_header->name) == -194 if (unlink(dst_name) == -1 56 95 && errno != ENOENT 57 96 ) { 58 97 bb_perror_msg_and_die("can't remove old file %s", 59 file_header->name);98 dst_name); 60 99 } 61 100 } … … 64 103 /* Remove the existing entry if its older than the extracted entry */ 65 104 struct stat existing_sb; 66 if (lstat( file_header->name, &existing_sb) == -1) {105 if (lstat(dst_name, &existing_sb) == -1) { 67 106 if (errno != ENOENT) { 68 107 bb_perror_msg_and_die("can't stat old file"); … … 74 113 ) { 75 114 bb_error_msg("%s not created: newer or " 76 "same age file exists", file_header->name);115 "same age file exists", dst_name); 77 116 } 78 117 data_skip(archive_handle); 79 118 goto ret; 80 119 } 81 else if ((unlink( file_header->name) == -1) && (errno != EISDIR)) {120 else if ((unlink(dst_name) == -1) && (errno != EISDIR)) { 82 121 bb_perror_msg_and_die("can't remove old file %s", 83 file_header->name); 84 } 85 } 86 87 /* Handle hard links separately 88 * We encode hard links as regular files of size 0 with a symlink */ 89 if (S_ISREG(file_header->mode) 90 && file_header->link_target 91 && file_header->size == 0 92 ) { 93 /* hard link */ 94 res = link(file_header->link_target, file_header->name); 95 if ((res == -1) && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) { 122 dst_name); 123 } 124 } 125 126 /* Handle hard links separately */ 127 if (hard_link) { 128 res = link(hard_link, dst_name); 129 if (res != 0 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET)) { 96 130 bb_perror_msg("can't create %slink " 97 131 "from %s to %s", "hard", 98 file_header->name,99 file_header->link_target);132 dst_name, 133 hard_link); 100 134 } 101 135 /* Hardlinks have no separate mode/ownership, skip chown/chmod */ … … 107 141 case S_IFREG: { 108 142 /* Regular file */ 143 char *dst_nameN; 109 144 int flags = O_WRONLY | O_CREAT | O_EXCL; 110 145 if (archive_handle->ah_flags & ARCHIVE_O_TRUNC) 111 146 flags = O_WRONLY | O_CREAT | O_TRUNC; 112 dst_fd = xopen3(file_header->name, 147 dst_nameN = dst_name; 148 #ifdef ARCHIVE_REPLACE_VIA_RENAME 149 if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME) 150 /* rpm-style temp file name */ 151 dst_nameN = xasprintf("%s;%x", dst_name, (int)getpid()); 152 #endif 153 dst_fd = xopen3(dst_nameN, 113 154 flags, 114 155 file_header->mode … … 116 157 bb_copyfd_exact_size(archive_handle->src_fd, dst_fd, file_header->size); 117 158 close(dst_fd); 159 #ifdef ARCHIVE_REPLACE_VIA_RENAME 160 if (archive_handle->ah_flags & ARCHIVE_REPLACE_VIA_RENAME) { 161 xrename(dst_nameN, dst_name); 162 free(dst_nameN); 163 } 164 #endif 118 165 break; 119 166 } 120 167 case S_IFDIR: 121 res = mkdir( file_header->name, file_header->mode);168 res = mkdir(dst_name, file_header->mode); 122 169 if ((res == -1) 123 170 && (errno != EISDIR) /* btw, Linux doesn't return this */ … … 125 172 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET) 126 173 ) { 127 bb_perror_msg("can't make dir %s", file_header->name);174 bb_perror_msg("can't make dir %s", dst_name); 128 175 } 129 176 break; … … 131 178 /* Symlink */ 132 179 //TODO: what if file_header->link_target == NULL (say, corrupted tarball?) 133 res = symlink(file_header->link_target, file_header->name);134 if ( (res == -1)180 res = symlink(file_header->link_target, dst_name); 181 if (res != 0 135 182 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET) 136 183 ) { 137 184 bb_perror_msg("can't create %slink " 138 185 "from %s to %s", "sym", 139 file_header->name,186 dst_name, 140 187 file_header->link_target); 141 188 } … … 145 192 case S_IFCHR: 146 193 case S_IFIFO: 147 res = mknod( file_header->name, file_header->mode, file_header->device);194 res = mknod(dst_name, file_header->mode, file_header->device); 148 195 if ((res == -1) 149 196 && !(archive_handle->ah_flags & ARCHIVE_EXTRACT_QUIET) 150 197 ) { 151 bb_perror_msg("can't create node %s", file_header->name);198 bb_perror_msg("can't create node %s", dst_name); 152 199 } 153 200 break; … … 174 221 #endif 175 222 /* GNU tar 1.15.1 uses chown, not lchown */ 176 chown( file_header->name, uid, gid);223 chown(dst_name, uid, gid); 177 224 } 178 225 /* uclibc has no lchmod, glibc is even stranger - … … 180 227 * so we use chmod... */ 181 228 if (!(archive_handle->ah_flags & ARCHIVE_DONT_RESTORE_PERM)) { 182 chmod( file_header->name, file_header->mode);229 chmod(dst_name, file_header->mode); 183 230 } 184 231 if (archive_handle->ah_flags & ARCHIVE_RESTORE_DATE) { … … 187 234 t[1].tv_sec = t[0].tv_sec = file_header->mtime; 188 235 t[1].tv_usec = t[0].tv_usec = 0; 189 utimes( file_header->name, t);236 utimes(dst_name, t); 190 237 } 191 238 } -
branches/3.3/mindi-busybox/archival/libarchive/data_extract_to_command.c
r3232 r3621 104 104 "-c", 105 105 archive_handle->tar__to_command, 106 NULL);106 (char *)0); 107 107 bb_perror_msg_and_die("can't execute '%s'", archive_handle->tar__to_command_shell); 108 108 } … … 113 113 close(p[1]); 114 114 115 if (safe_waitpid(pid, &status, 0) == -1) 116 bb_perror_msg_and_die("waitpid"); 115 status = wait_for_exitstatus(pid); 117 116 if (WIFEXITED(status) && WEXITSTATUS(status)) 118 117 bb_error_msg_and_die("'%s' returned status %d", 119 118 archive_handle->tar__to_command, WEXITSTATUS(status)); 120 119 if (WIFSIGNALED(status)) 121 bb_error_msg_and_die("'%s' terminated onsignal %d",120 bb_error_msg_and_die("'%s' terminated by signal %d", 122 121 archive_handle->tar__to_command, WTERMSIG(status)); 123 122 -
branches/3.3/mindi-busybox/archival/libarchive/decompress_bunzip2.c
r3232 r3621 43 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 51 /* Constants for Huffman coding */ 46 52 #define MAX_GROUPS 6 … … 53 59 /* Status return values */ 54 60 #define RETVAL_OK 0 55 #define RETVAL_LAST_BLOCK ( -1)56 #define RETVAL_NOT_BZIP_DATA ( -2)57 #define RETVAL_UNEXPECTED_INPUT_EOF ( -3)58 #define RETVAL_SHORT_WRITE ( -4)59 #define RETVAL_DATA_ERROR ( -5)60 #define RETVAL_OUT_OF_MEMORY ( -6)61 #define RETVAL_OBSOLETE_INPUT ( -7)61 #define RETVAL_LAST_BLOCK (dbg("%d", __LINE__), -1) 62 #define RETVAL_NOT_BZIP_DATA (dbg("%d", __LINE__), -2) 63 #define RETVAL_UNEXPECTED_INPUT_EOF (dbg("%d", __LINE__), -3) 64 #define RETVAL_SHORT_WRITE (dbg("%d", __LINE__), -4) 65 #define RETVAL_DATA_ERROR (dbg("%d", __LINE__), -5) 66 #define RETVAL_OUT_OF_MEMORY (dbg("%d", __LINE__), -6) 67 #define RETVAL_OBSOLETE_INPUT (dbg("%d", __LINE__), -7) 62 68 63 69 /* Other housekeeping constants */ … … 441 447 if (runPos != 0) { 442 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 454 tmp_byte = symToByte[mtfSymbol[0]]; 445 455 byteCount[tmp_byte] += runCnt; … … 722 732 /* Decompress src_fd to dst_fd. Stops at end of bzip data, not end of file. */ 723 733 IF_DESKTOP(long long) int FAST_FUNC 724 unpack_bz2_stream(transformer_ aux_data_t *aux, int src_fd, int dst_fd)734 unpack_bz2_stream(transformer_state_t *xstate) 725 735 { 726 736 IF_DESKTOP(long long total_written = 0;) … … 730 740 unsigned len; 731 741 732 if (check_signature16( aux, src_fd, BZIP2_MAGIC))742 if (check_signature16(xstate, BZIP2_MAGIC)) 733 743 return -1; 734 744 … … 737 747 while (1) { /* "Process one BZ... stream" loop */ 738 748 739 i = start_bunzip(&bd, src_fd, outbuf + 2, len);749 i = start_bunzip(&bd, xstate->src_fd, outbuf + 2, len); 740 750 741 751 if (i == 0) { … … 747 757 if (i == 0) /* EOF? */ 748 758 break; 749 if (i != full_write(dst_fd, outbuf, i)) { 750 bb_error_msg("short write"); 759 if (i != transformer_write(xstate, outbuf, i)) { 751 760 i = RETVAL_SHORT_WRITE; 752 761 goto release_mem; … … 781 790 memcpy(outbuf, &bd->inbuf[bd->inbufPos], len); 782 791 if (len < 2) { 783 if (safe_read( src_fd, outbuf + len, 2 - len) != 2 - len)792 if (safe_read(xstate->src_fd, outbuf + len, 2 - len) != 2 - len) 784 793 break; 785 794 len = 2; … … 809 818 int main(int argc, char **argv) 810 819 { 811 int i;812 820 char c; 813 821 -
branches/3.3/mindi-busybox/archival/libarchive/decompress_gunzip.c
r3233 r3621 306 306 unsigned j; /* counter */ 307 307 int k; /* number of bits in current code */ 308 unsigned *p;/* pointer into c[], b[], or v[] */308 const unsigned *p; /* pointer into c[], b[], or v[] */ 309 309 huft_t *q; /* points to current table */ 310 310 huft_t r; /* table entry for structure assignment */ 311 311 huft_t *u[BMAX]; /* table stack */ 312 unsigned v[N_MAX ]; /* values in order of bit length*/312 unsigned v[N_MAX + 1]; /* values in order of bit length. last v[] is never used */ 313 313 int ws[BMAX + 1]; /* bits decoded stack */ 314 314 int w; /* bits decoded */ … … 325 325 /* Generate counts for each bit length */ 326 326 memset(c, 0, sizeof(c)); 327 p = (unsigned *) b; /* cast allows us to reuse p for pointing to b */327 p = b; 328 328 i = n; 329 329 do { … … 337 337 338 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 340 continue; 341 341 k = j; /* minimum code length */ … … 365 365 } 366 366 367 /* Make a table of values in order of bit lengths */ 368 p = (unsigned *) b; 367 /* Make a table of values in order of bit lengths. 368 * To detect bad input, unused v[i]'s are set to invalid value UINT_MAX. 369 * In particular, last v[i] is never filled and must not be accessed. 370 */ 371 memset(v, 0xff, sizeof(v)); 372 p = b; 369 373 i = 0; 370 374 do { … … 433 437 /* set up table entry in r */ 434 438 r.b = (unsigned char) (k - w); 435 if (p >= v + n) { 439 if (/*p >= v + n || -- redundant, caught by the second check: */ 440 *p == UINT_MAX /* do we access uninited v[i]? (see memset(v))*/ 441 ) { 436 442 r.e = 99; /* out of values--invalid code */ 437 443 } else if (*p < s) { … … 518 524 if (e > 16) 519 525 do { 520 if (e == 99) 521 abort_unzip(PASS_STATE_ONLY);; 526 if (e == 99) { 527 abort_unzip(PASS_STATE_ONLY); 528 } 522 529 bb >>= t->b; 523 530 k -= t->b; … … 555 562 if (e > 16) 556 563 do { 557 if (e == 99) 564 if (e == 99) { 558 565 abort_unzip(PASS_STATE_ONLY); 566 } 559 567 bb >>= t->b; 560 568 k -= t->b; … … 822 830 b_dynamic >>= 4; 823 831 k_dynamic -= 4; 824 if (nl > 286 || nd > 30) 832 if (nl > 286 || nd > 30) { 825 833 abort_unzip(PASS_STATE_ONLY); /* bad lengths */ 834 } 826 835 827 836 /* read in bit-length-code lengths */ … … 904 913 905 914 i = huft_build(ll, nl, 257, cplens, cplext, &inflate_codes_tl, &bl); 906 if (i != 0) 915 if (i != 0) { 907 916 abort_unzip(PASS_STATE_ONLY); 917 } 908 918 bd = dbits; 909 919 i = huft_build(ll + nl, nd, 0, cpdist, cpdext, &inflate_codes_td, &bd); 910 if (i != 0) 920 if (i != 0) { 911 921 abort_unzip(PASS_STATE_ONLY); 922 } 912 923 913 924 /* set up data for inflate_codes() */ … … 972 983 /* Called from unpack_gz_stream() and inflate_unzip() */ 973 984 static IF_DESKTOP(long long) int 974 inflate_unzip_internal(STATE_PARAM int in, int out)985 inflate_unzip_internal(STATE_PARAM transformer_state_t *xstate) 975 986 { 976 987 IF_DESKTOP(long long) int n = 0; … … 981 992 gunzip_outbuf_count = 0; 982 993 gunzip_bytes_out = 0; 983 gunzip_src_fd = in;994 gunzip_src_fd = xstate->src_fd; 984 995 985 996 /* (re) initialize state */ … … 997 1008 if (setjmp(error_jmp)) { 998 1009 /* Error from deep inside zip machinery */ 1010 bb_error_msg(error_msg); 999 1011 n = -1; 1000 1012 goto ret; … … 1003 1015 while (1) { 1004 1016 int r = inflate_get_next_window(PASS_STATE_ONLY); 1005 nwrote = full_write(out, gunzip_window, gunzip_outbuf_count); 1006 if (nwrote != (ssize_t)gunzip_outbuf_count) { 1007 bb_perror_msg("write"); 1017 nwrote = transformer_write(xstate, gunzip_window, gunzip_outbuf_count); 1018 if (nwrote == (ssize_t)-1) { 1008 1019 n = -1; 1009 1020 goto ret; … … 1035 1046 1036 1047 IF_DESKTOP(long long) int FAST_FUNC 1037 inflate_unzip(transformer_ aux_data_t *aux, int in, int out)1048 inflate_unzip(transformer_state_t *xstate) 1038 1049 { 1039 1050 IF_DESKTOP(long long) int n; … … 1042 1053 ALLOC_STATE; 1043 1054 1044 to_read = aux->bytes_in;1055 to_read = xstate->bytes_in; 1045 1056 // bytebuffer_max = 0x8000; 1046 1057 bytebuffer_offset = 4; 1047 1058 bytebuffer = xmalloc(bytebuffer_max); 1048 n = inflate_unzip_internal(PASS_STATE in, out);1059 n = inflate_unzip_internal(PASS_STATE xstate); 1049 1060 free(bytebuffer); 1050 1061 1051 aux->crc32 = gunzip_crc;1052 aux->bytes_out = gunzip_bytes_out;1062 xstate->crc32 = gunzip_crc; 1063 xstate->bytes_out = gunzip_bytes_out; 1053 1064 DEALLOC_STATE; 1054 1065 return n; … … 1108 1119 } 1109 1120 1110 static int check_header_gzip(STATE_PARAM transformer_ aux_data_t *aux)1121 static int check_header_gzip(STATE_PARAM transformer_state_t *xstate) 1111 1122 { 1112 1123 union { … … 1120 1131 } PACKED formatted; 1121 1132 } header; 1122 struct BUG_header { 1123 char BUG_header[sizeof(header) == 8 ? 1 : -1]; 1124 }; 1133 1134 BUILD_BUG_ON(sizeof(header) != 8); 1125 1135 1126 1136 /* … … 1170 1180 } 1171 1181 1172 if (aux) 1173 aux->mtime = SWAP_LE32(header.formatted.mtime); 1182 xstate->mtime = SWAP_LE32(header.formatted.mtime); 1174 1183 1175 1184 /* Read the header checksum */ … … 1183 1192 1184 1193 IF_DESKTOP(long long) int FAST_FUNC 1185 unpack_gz_stream(transformer_ aux_data_t *aux, int src_fd, int dst_fd)1194 unpack_gz_stream(transformer_state_t *xstate) 1186 1195 { 1187 1196 uint32_t v32; … … 1190 1199 1191 1200 #if !ENABLE_FEATURE_SEAMLESS_Z 1192 if (check_signature16( aux, src_fd, GZIP_MAGIC))1201 if (check_signature16(xstate, GZIP_MAGIC)) 1193 1202 return -1; 1194 1203 #else 1195 if ( aux && aux->check_signature) {1204 if (!xstate->signature_skipped) { 1196 1205 uint16_t magic2; 1197 1206 1198 if (full_read( src_fd, &magic2, 2) != 2) {1207 if (full_read(xstate->src_fd, &magic2, 2) != 2) { 1199 1208 bad_magic: 1200 1209 bb_error_msg("invalid magic"); … … 1202 1211 } 1203 1212 if (magic2 == COMPRESS_MAGIC) { 1204 aux->check_signature = 0;1205 return unpack_Z_stream( aux, src_fd, dst_fd);1213 xstate->signature_skipped = 2; 1214 return unpack_Z_stream(xstate); 1206 1215 } 1207 1216 if (magic2 != GZIP_MAGIC) … … 1216 1225 // bytebuffer_max = 0x8000; 1217 1226 bytebuffer = xmalloc(bytebuffer_max); 1218 gunzip_src_fd = src_fd;1227 gunzip_src_fd = xstate->src_fd; 1219 1228 1220 1229 again: 1221 if (!check_header_gzip(PASS_STATE aux)) {1230 if (!check_header_gzip(PASS_STATE xstate)) { 1222 1231 bb_error_msg("corrupted data"); 1223 1232 total = -1; … … 1225 1234 } 1226 1235 1227 n = inflate_unzip_internal(PASS_STATE src_fd, dst_fd);1236 n = inflate_unzip_internal(PASS_STATE xstate); 1228 1237 if (n < 0) { 1229 1238 total = -1; -
branches/3.3/mindi-busybox/archival/libarchive/decompress_uncompress.c
r3232 r3621 74 74 75 75 IF_DESKTOP(long long) int FAST_FUNC 76 unpack_Z_stream(transformer_ aux_data_t *aux, int src_fd, int dst_fd)76 unpack_Z_stream(transformer_state_t *xstate) 77 77 { 78 78 IF_DESKTOP(long long total_written = 0;) … … 103 103 int block_mode; /* = BLOCK_MODE; */ 104 104 105 if (check_signature16( aux, src_fd, COMPRESS_MAGIC))105 if (check_signature16(xstate, COMPRESS_MAGIC)) 106 106 return -1; 107 107 … … 115 115 /* xread isn't good here, we have to return - caller may want 116 116 * to do some cleanup (e.g. delete incomplete unpacked file etc) */ 117 if (full_read( src_fd, inbuf, 1) != 1) {117 if (full_read(xstate->src_fd, inbuf, 1) != 1) { 118 118 bb_error_msg("short read"); 119 119 goto err; … … 167 167 168 168 if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) { 169 rsize = safe_read( src_fd, inbuf + insize, IBUFSIZ);169 rsize = safe_read(xstate->src_fd, inbuf + insize, IBUFSIZ); 170 170 if (rsize < 0) 171 171 bb_error_msg_and_die(bb_msg_read_error); … … 275 275 276 276 if (outpos >= OBUFSIZ) { 277 x write(dst_fd, outbuf, outpos);277 xtransformer_write(xstate, outbuf, outpos); 278 278 IF_DESKTOP(total_written += outpos;) 279 279 outpos = 0; … … 298 298 oldcode = incode; 299 299 } 300 301 300 } while (rsize > 0); 302 301 303 302 if (outpos > 0) { 304 x write(dst_fd, outbuf, outpos);303 xtransformer_write(xstate, outbuf, outpos); 305 304 IF_DESKTOP(total_written += outpos;) 306 305 } -
branches/3.3/mindi-busybox/archival/libarchive/decompress_unlzma.c
r3232 r3621 46 46 47 47 48 /* Called twice: once at startup (LZMA_FAST only) and once in rc_normalize() */49 static size_inlinevoid rc_read(rc_t *rc)48 /* Called once in rc_do_normalize() */ 49 static void rc_read(rc_t *rc) 50 50 { 51 51 int buffer_size = safe_read(rc->fd, RC_BUFFER, RC_BUFFER_SIZE); … … 54 54 if (buffer_size <= 0) 55 55 bb_error_msg_and_die("unexpected EOF"); 56 rc->buffer_end = RC_BUFFER + buffer_size; 56 57 rc->ptr = RC_BUFFER; 57 rc->buffer_end = RC_BUFFER + buffer_size;58 58 } 59 59 … … 66 66 rc->code = (rc->code << 8) | *rc->ptr++; 67 67 } 68 static ALWAYS_INLINE void rc_normalize(rc_t *rc) 69 { 70 if (rc->range < (1 << RC_TOP_BITS)) { 71 rc_do_normalize(rc); 72 } 73 } 68 74 69 75 /* Called once */ … … 79 85 80 86 for (i = 0; i < 5; i++) { 81 #if ENABLE_FEATURE_LZMA_FAST82 if (rc->ptr >= rc->buffer_end)83 rc_read(rc);84 rc->code = (rc->code << 8) | *rc->ptr++;85 #else86 87 rc_do_normalize(rc); 87 #endif 88 } 89 rc->range = 0xFFFFFFFF; 88 } 89 rc->range = 0xffffffff; 90 90 return rc; 91 91 } … … 95 95 { 96 96 free(rc); 97 }98 99 static ALWAYS_INLINE void rc_normalize(rc_t *rc)100 {101 if (rc->range < (1 << RC_TOP_BITS)) {102 rc_do_normalize(rc);103 }104 97 } 105 98 … … 121 114 122 115 /* Called 4 times in unlzma loop */ 123 static speed_inlineint rc_get_bit(rc_t *rc, uint16_t *p, int *symbol)116 static ALWAYS_INLINE int rc_get_bit(rc_t *rc, uint16_t *p, int *symbol) 124 117 { 125 118 int ret = rc_is_bit_1(rc, p); … … 214 207 215 208 IF_DESKTOP(long long) int FAST_FUNC 216 unpack_lzma_stream(transformer_ aux_data_t *aux UNUSED_PARAM, int src_fd, int dst_fd)209 unpack_lzma_stream(transformer_state_t *xstate) 217 210 { 218 211 IF_DESKTOP(long long total_written = 0;) … … 222 215 uint32_t literal_pos_mask; 223 216 uint16_t *p; 224 int num_bits;225 int num_probs;226 217 rc_t *rc; 227 218 int i; … … 233 224 uint32_t rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1; 234 225 235 if (full_read( src_fd, &header, sizeof(header)) != sizeof(header)226 if (full_read(xstate->src_fd, &header, sizeof(header)) != sizeof(header) 236 227 || header.pos >= (9 * 5 * 5) 237 228 ) { … … 247 238 literal_pos_mask = (1 << lp) - 1; 248 239 240 /* Example values from linux-3.3.4.tar.lzma: 241 * dict_size: 64M, dst_size: 2^64-1 242 */ 249 243 header.dict_size = SWAP_LE32(header.dict_size); 250 244 header.dst_size = SWAP_LE64(header.dst_size); … … 255 249 buffer = xmalloc(MIN(header.dst_size, header.dict_size)); 256 250 257 num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)); 258 p = xmalloc(num_probs * sizeof(*p)); 259 num_probs += LZMA_LITERAL - LZMA_BASE_SIZE; 260 for (i = 0; i < num_probs; i++) 261 p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1; 262 263 rc = rc_init(src_fd); /*, RC_BUFFER_SIZE); */ 251 { 252 int num_probs; 253 254 num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)); 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 } 260 261 rc = rc_init(xstate->src_fd); /*, RC_BUFFER_SIZE); */ 264 262 265 263 while (global_pos + buffer_pos < header.dst_size) { … … 309 307 buffer_pos = 0; 310 308 global_pos += header.dict_size; 311 if ( full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)309 if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size) 312 310 goto bad; 313 311 IF_DESKTOP(total_written += header.dict_size;) … … 318 316 #endif 319 317 } else { 318 int num_bits; 320 319 int offset; 321 320 uint16_t *prob2; … … 442 441 buffer_pos = 0; 443 442 global_pos += header.dict_size; 444 if ( full_write(dst_fd, buffer, header.dict_size) != (ssize_t)header.dict_size)443 if (transformer_write(xstate, buffer, header.dict_size) != (ssize_t)header.dict_size) 445 444 goto bad; 446 445 IF_DESKTOP(total_written += header.dict_size;) … … 448 447 len--; 449 448 } while (len != 0 && buffer_pos < header.dst_size); 449 /* FIXME: ...........^^^^^ 450 * shouldn't it be "global_pos + buffer_pos < header.dst_size"? 451 */ 450 452 } 451 453 } … … 454 456 IF_NOT_DESKTOP(int total_written = 0; /* success */) 455 457 IF_DESKTOP(total_written += buffer_pos;) 456 if ( full_write(dst_fd, buffer, buffer_pos) != (ssize_t)buffer_pos) {458 if (transformer_write(xstate, buffer, buffer_pos) != (ssize_t)buffer_pos) { 457 459 bad: 458 460 total_written = -1; /* failure */ -
branches/3.3/mindi-busybox/archival/libarchive/decompress_unxz.c
r3232 r3621 39 39 40 40 IF_DESKTOP(long long) int FAST_FUNC 41 unpack_xz_stream(transformer_ aux_data_t *aux, int src_fd, int dst_fd)41 unpack_xz_stream(transformer_state_t *xstate) 42 42 { 43 43 enum xz_ret xz_result; … … 56 56 iobuf.out_size = BUFSIZ; 57 57 58 if (! aux || aux->check_signature == 0) {58 if (!xstate || xstate->signature_skipped) { 59 59 /* Preload XZ file signature */ 60 60 strcpy((char*)membuf, HEADER_MAGIC); … … 68 68 while (1) { 69 69 if (iobuf.in_pos == iobuf.in_size) { 70 int rd = safe_read( src_fd, membuf, BUFSIZ);70 int rd = safe_read(xstate->src_fd, membuf, BUFSIZ); 71 71 if (rd < 0) { 72 72 bb_error_msg(bb_msg_read_error); … … 105 105 // iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, xz_result); 106 106 if (iobuf.out_pos) { 107 x write(dst_fd, iobuf.out, iobuf.out_pos);107 xtransformer_write(xstate, iobuf.out, iobuf.out_pos); 108 108 IF_DESKTOP(total += iobuf.out_pos;) 109 109 iobuf.out_pos = 0; -
branches/3.3/mindi-busybox/archival/libarchive/filter_accept_list_reassign.c
r3232 r3621 29 29 30 30 /* Modify the subarchive handler based on the extension */ 31 if (strcmp(name_ptr, "tar") == 0) { 32 archive_handle->dpkg__action_data_subarchive = get_header_tar; 33 return EXIT_SUCCESS; 34 } 31 35 if (ENABLE_FEATURE_SEAMLESS_GZ 32 36 && strcmp(name_ptr, "gz") == 0 … … 47 51 return EXIT_SUCCESS; 48 52 } 53 if (ENABLE_FEATURE_SEAMLESS_XZ 54 && strcmp(name_ptr, "xz") == 0 55 ) { 56 archive_handle->dpkg__action_data_subarchive = get_header_tar_xz; 57 return EXIT_SUCCESS; 58 } 49 59 } 50 60 return EXIT_FAILURE; -
branches/3.3/mindi-busybox/archival/libarchive/get_header_ar.c
r3232 r3621 9 9 #include "ar.h" 10 10 11 static unsigned read_num(const char *str, int base) 11 /* WARNING: Clobbers str[len], so fields must be read in reverse order! */ 12 static 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 21 /* This code works because 14 22 * on misformatted numbers bb_strtou returns all-ones */ 15 interr = bb_strtou(str, NULL, base);23 err = bb_strtou(str, NULL, base); 16 24 if (err == -1) 17 25 bb_error_msg_and_die("invalid ar header"); … … 52 60 bb_error_msg_and_die("invalid ar header"); 53 61 54 /* FIXME: more thorough routine would be in order here 55 * (we have something like that in tar) 56 * but for now we are lax. */ 57 ar.formatted.magic[0] = '\0'; /* else 4G-2 file will have size="4294967294`\n..." */ 58 typed->size = size = read_num(ar.formatted.size, 10); 62 /* 63 * Note that the fields MUST be read in reverse order as 64 * read_num() clobbers the next byte after the field! 65 * Order is: name, date, uid, gid, mode, size, magic. 66 */ 67 typed->size = size = read_num(ar.formatted.size, 10, 68 sizeof(ar.formatted.size)); 59 69 60 70 /* special filenames have '/' as the first character */ … … 88 98 * after dealing with long filename pseudo file. 89 99 */ 90 typed->mode = read_num(ar.formatted.mode, 8 );91 typed-> mtime = read_num(ar.formatted.date, 10);92 typed->uid = read_num(ar.formatted.uid, 10 );93 typed-> gid = read_num(ar.formatted.gid, 10);100 typed->mode = read_num(ar.formatted.mode, 8, sizeof(ar.formatted.mode)); 101 typed->gid = read_num(ar.formatted.gid, 10, sizeof(ar.formatted.gid)); 102 typed->uid = read_num(ar.formatted.uid, 10, sizeof(ar.formatted.uid)); 103 typed->mtime = read_num(ar.formatted.date, 10, sizeof(ar.formatted.date)); 94 104 95 105 #if ENABLE_FEATURE_AR_LONG_FILENAMES … … 99 109 /* The number after the '/' indicates the offset in the ar data section 100 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 113 if (long_offset >= ar_long_name_size) { 103 114 bb_error_msg_and_die("can't resolve long filename"); -
branches/3.3/mindi-busybox/archival/libarchive/get_header_cpio.c
r3232 r3621 38 38 archive_handle->offset += 110; 39 39 40 if ( strncmp(&cpio_header[0], "07070", 5) != 040 if (!is_prefixed_with(&cpio_header[0], "07070") 41 41 || (cpio_header[5] != '1' && cpio_header[5] != '2') 42 42 ) { … … 53 53 bb_error_msg_and_die("damaged cpio file"); 54 54 file_header->mode = mode; 55 /* "cpio -R USER:GRP" support: */ 56 if (archive_handle->cpio__owner.uid != (uid_t)-1L) 57 uid = archive_handle->cpio__owner.uid; 58 if (archive_handle->cpio__owner.gid != (gid_t)-1L) 59 gid = archive_handle->cpio__owner.gid; 55 60 file_header->uid = uid; 56 61 file_header->gid = gid; … … 76 81 data_align(archive_handle, 4); 77 82 78 if (strcmp(file_header->name, "TRAILER!!!") == 0) {83 if (strcmp(file_header->name, cpio_TRAILER) == 0) { 79 84 /* Always round up. ">> 9" divides by 512 */ 80 85 archive_handle->cpio__blocks = (uoff_t)(archive_handle->offset + 511) >> 9; -
branches/3.3/mindi-busybox/archival/libarchive/get_header_tar.c
r3232 r3621 17 17 typedef uint32_t aliased_uint32_t FIX_ALIASING; 18 18 typedef off_t aliased_off_t FIX_ALIASING; 19 20 21 const char* FAST_FUNC strip_unsafe_prefix(const char *str)22 {23 const char *cp = str;24 while (1) {25 char *cp2;26 if (*cp == '/') {27 cp++;28 continue;29 }30 if (strncmp(cp, "/../"+1, 3) == 0) {31 cp += 3;32 continue;33 }34 cp2 = strstr(cp, "/../");35 if (!cp2)36 break;37 cp = cp2 + 4;38 }39 if (cp != str) {40 static smallint warned = 0;41 if (!warned) {42 warned = 1;43 bb_error_msg("removing leading '%.*s' from member names",44 (int)(cp - str), str);45 }46 }47 return cp;48 }49 19 50 20 /* NB: _DESTROYS_ str[len] character! */ … … 91 61 #define GET_OCTAL(a) getOctal((a), sizeof(a)) 92 62 63 #define TAR_EXTD (ENABLE_FEATURE_TAR_GNU_EXTENSIONS || ENABLE_FEATURE_TAR_SELINUX) 64 #if !TAR_EXTD 65 #define process_pax_hdr(archive_handle, sz, global) \ 66 process_pax_hdr(archive_handle, sz) 67 #endif 93 68 /* "global" is 0 or 1 */ 94 69 static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int global) 95 70 { 71 #if !TAR_EXTD 72 unsigned blk_sz = (sz + 511) & (~511); 73 seek_by_read(archive_handle->src_fd, blk_sz); 74 #else 75 unsigned blk_sz = (sz + 511) & (~511); 96 76 char *buf, *p; 97 unsigned blk_sz; 98 99 blk_sz = (sz + 511) & (~511); 77 100 78 p = buf = xmalloc(blk_sz + 1); 101 79 xread(archive_handle->src_fd, buf, blk_sz); … … 116 94 p += len; 117 95 sz -= len; 118 if ((int)sz < 0 96 if ( 97 /** (int)sz < 0 - not good enough for huge malicious VALUE of 2^32-1 */ 98 (int)(sz|len) < 0 /* this works */ 119 99 || len == 0 120 100 || errno != EINVAL … … 133 113 value = end + 1; 134 114 135 # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS136 if (!global && strncmp(value, "path=", sizeof("path=") - 1) == 0) {115 # if ENABLE_FEATURE_TAR_GNU_EXTENSIONS 116 if (!global && is_prefixed_with(value, "path=")) { 137 117 value += sizeof("path=") - 1; 138 118 free(archive_handle->tar__longname); … … 140 120 continue; 141 121 } 142 # endif143 144 # if ENABLE_FEATURE_TAR_SELINUX122 # endif 123 124 # if ENABLE_FEATURE_TAR_SELINUX 145 125 /* Scan for SELinux contexts, via "RHT.security.selinux" keyword. 146 126 * This is what Red Hat's patched version of tar uses. 147 127 */ 148 # define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"149 if ( strncmp(value, SELINUX_CONTEXT_KEYWORD"=", sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1) == 0) {128 # define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux" 129 if (is_prefixed_with(value, SELINUX_CONTEXT_KEYWORD"=")) { 150 130 value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1; 151 131 free(archive_handle->tar__sctx[global]); … … 153 133 continue; 154 134 } 155 # endif135 # endif 156 136 } 157 137 158 138 free(buf); 139 #endif 159 140 } 160 141 … … 199 180 * saw zero block directly before this. */ 200 181 if (i == 0) { 201 xfunc_error_retval = 0;202 short_read: 203 bb_error_msg_and_die("short read");182 bb_error_msg("short read"); 183 /* this merely signals end of archive, not exit(1): */ 184 return EXIT_FAILURE; 204 185 } 205 186 if (i != 512) { 206 187 IF_FEATURE_TAR_AUTODETECT(goto autodetect;) 207 goto short_read;188 bb_error_msg_and_die("short read"); 208 189 } 209 190 … … 222 203 while (full_read(archive_handle->src_fd, &tar, 512) == 512) 223 204 continue; 224 return EXIT_FAILURE; 205 return EXIT_FAILURE; /* "end of archive" */ 225 206 } 226 207 archive_handle->tar__end = 1; 227 return EXIT_SUCCESS; 208 return EXIT_SUCCESS; /* "decoded one header" */ 228 209 } 229 210 archive_handle->tar__end = 0; … … 231 212 /* Check header has valid magic, "ustar" is for the proper tar, 232 213 * five NULs are for the old tar format */ 233 if ( strncmp(tar.magic, "ustar", 5) != 0214 if (!is_prefixed_with(tar.magic, "ustar") 234 215 && (!ENABLE_FEATURE_TAR_OLDGNU_COMPATIBILITY 235 216 || memcmp(tar.magic, "\0\0\0\0", 5) != 0) … … 242 223 if (lseek(archive_handle->src_fd, -i, SEEK_CUR) != 0) 243 224 goto err; 244 if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_ detected:*/ 0) != 0)225 if (setup_unzip_on_fd(archive_handle->src_fd, /*fail_if_not_compressed:*/ 0) != 0) 245 226 err: 246 227 bb_error_msg_and_die("invalid tar magic"); … … 379 360 file_header->mode |= S_IFIFO; 380 361 goto size0; 362 case 'g': /* pax global header */ 363 case 'x': { /* pax extended header */ 364 if ((uoff_t)file_header->size > 0xfffff) /* paranoia */ 365 goto skip_ext_hdr; 366 process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g')); 367 goto again_after_align; 381 368 #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS 369 /* See http://www.gnu.org/software/tar/manual/html_node/Extensions.html */ 382 370 case 'L': 383 371 /* free: paranoia: tar with several consecutive longnames */ … … 399 387 /* return get_header_tar(archive_handle); */ 400 388 goto again; 401 case 'D': /* GNU dump dir */ 402 case 'M': /* Continuation of multi volume archive */ 403 case 'N': /* Old GNU for names > 100 characters */ 404 case 'S': /* Sparse file */ 405 case 'V': /* Volume header */ 406 #endif 407 case 'g': /* pax global header */ 408 case 'x': { /* pax extended header */ 409 if ((uoff_t)file_header->size > 0xfffff) /* paranoia */ 410 goto skip_ext_hdr; 411 process_pax_hdr(archive_handle, file_header->size, (tar.typeflag == 'g')); 412 goto again_after_align; 389 /* 390 * case 'S': // Sparse file 391 * Was seen in the wild. Not supported (yet?). 392 * See https://www.gnu.org/software/tar/manual/html_section/tar_92.html 393 * for the format. (An "Old GNU Format" was seen, not PAX formats). 394 */ 395 // case 'D': /* GNU dump dir */ 396 // case 'M': /* Continuation of multi volume archive */ 397 // case 'N': /* Old GNU for names > 100 characters */ 398 // case 'V': /* Volume header */ 399 #endif 413 400 } 414 401 skip_ext_hdr: … … 441 428 /* Everything up to and including last ".." component is stripped */ 442 429 overlapping_strcpy(file_header->name, strip_unsafe_prefix(file_header->name)); 430 //TODO: do the same for file_header->link_target? 443 431 444 432 /* Strip trailing '/' in directories */ … … 472 460 free(file_header->tar__gname); 473 461 #endif 474 return EXIT_SUCCESS; 462 return EXIT_SUCCESS; /* "decoded one header" */ 475 463 } -
branches/3.3/mindi-busybox/archival/libarchive/get_header_tar_bz2.c
r3232 r3621 12 12 archive_handle->seek = seek_by_read; 13 13 14 open_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2");14 fork_transformer_with_sig(archive_handle->src_fd, unpack_bz2_stream, "bunzip2"); 15 15 archive_handle->offset = 0; 16 16 while (get_header_tar(archive_handle) == EXIT_SUCCESS) -
branches/3.3/mindi-busybox/archival/libarchive/get_header_tar_gz.c
r3232 r3621 12 12 archive_handle->seek = seek_by_read; 13 13 14 open_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip");14 fork_transformer_with_sig(archive_handle->src_fd, unpack_gz_stream, "gunzip"); 15 15 archive_handle->offset = 0; 16 16 while (get_header_tar(archive_handle) == EXIT_SUCCESS) -
branches/3.3/mindi-busybox/archival/libarchive/get_header_tar_lzma.c
r3232 r3621 15 15 archive_handle->seek = seek_by_read; 16 16 17 open_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma");17 fork_transformer_with_sig(archive_handle->src_fd, unpack_lzma_stream, "unlzma"); 18 18 archive_handle->offset = 0; 19 19 while (get_header_tar(archive_handle) == EXIT_SUCCESS) -
branches/3.3/mindi-busybox/archival/libarchive/liblzo.h
r2725 r3621 77 77 # define NEED_IP(x) \ 78 78 if ((unsigned)(ip_end - ip) < (unsigned)(x)) goto input_overrun 79 # define TEST_IV(x) if ((x) > (unsigned)0 - (511)) goto input_overrun 79 80 80 81 # undef TEST_OP /* don't need both of the tests here */ … … 82 83 # define NEED_OP(x) \ 83 84 if ((unsigned)(op_end - op) < (unsigned)(x)) goto output_overrun 85 # define TEST_OV(x) if ((x) > (unsigned)0 - (511)) goto output_overrun 84 86 85 87 #define HAVE_ANY_OP 1 -
branches/3.3/mindi-busybox/archival/libarchive/lzo1x_9x.c
r3232 r3621 72 72 73 73 unsigned r1_lit; 74 75 74 } lzo1x_999_t; 76 75 … … 95 94 96 95 #if defined(LZO_UNALIGNED_OK_2) 97 # define HEAD2(b,p) (* ( uint16_t *) &(b[p]))96 # define HEAD2(b,p) (* (bb__aliased_uint16_t *) &(b[p])) 98 97 #else 99 98 # define HEAD2(b,p) (b[p] ^ ((unsigned)b[p+1]<<8)) … … 466 465 } 467 466 468 s->m_len = 1;469 467 s->m_len = 1; 470 468 #ifdef SWD_BEST_OFF -
branches/3.3/mindi-busybox/archival/libarchive/lzo1x_d.c
r3232 r3621 93 93 NEED_IP(1); 94 94 } 95 TEST_IV(t); 95 96 t += 15 + *ip++; 96 97 } … … 225 226 NEED_IP(1); 226 227 } 228 TEST_IV(t); 227 229 t += 31 + *ip++; 228 230 } … … 266 268 NEED_IP(1); 267 269 } 270 TEST_IV(t); 268 271 t += 7 + *ip++; 269 272 } -
branches/3.3/mindi-busybox/archival/libarchive/open_transformer.c
r3232 r3621 7 7 #include "bb_archive.h" 8 8 9 void FAST_FUNC init_transformer_ aux_data(transformer_aux_data_t *aux)10 { 11 memset( aux, 0, sizeof(*aux));12 } 13 14 int FAST_FUNC check_signature16(transformer_ aux_data_t *aux, int src_fd, unsigned magic16)15 { 16 if ( aux && aux->check_signature) {9 void FAST_FUNC init_transformer_state(transformer_state_t *xstate) 10 { 11 memset(xstate, 0, sizeof(*xstate)); 12 } 13 14 int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16) 15 { 16 if (!xstate->signature_skipped) { 17 17 uint16_t magic2; 18 if (full_read( src_fd, &magic2, 2) != 2 || magic2 != magic16) {18 if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) { 19 19 bb_error_msg("invalid magic"); 20 #if 0 /* possible future extension */21 if (aux->check_signature > 1)22 xfunc_die();23 #endif24 20 return -1; 25 21 } 22 xstate->signature_skipped = 2; 26 23 } 27 24 return 0; 25 } 26 27 ssize_t FAST_FUNC transformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize) 28 { 29 ssize_t nwrote; 30 31 if (xstate->mem_output_size_max != 0) { 32 size_t pos = xstate->mem_output_size; 33 size_t size; 34 35 size = (xstate->mem_output_size += bufsize); 36 if (size > xstate->mem_output_size_max) { 37 free(xstate->mem_output_buf); 38 xstate->mem_output_buf = NULL; 39 bb_perror_msg("buffer %u too small", (unsigned)xstate->mem_output_size_max); 40 nwrote = -1; 41 goto ret; 42 } 43 xstate->mem_output_buf = xrealloc(xstate->mem_output_buf, size + 1); 44 memcpy(xstate->mem_output_buf + pos, buf, bufsize); 45 xstate->mem_output_buf[size] = '\0'; 46 nwrote = bufsize; 47 } else { 48 nwrote = full_write(xstate->dst_fd, buf, bufsize); 49 if (nwrote != (ssize_t)bufsize) { 50 bb_perror_msg("write"); 51 nwrote = -1; 52 goto ret; 53 } 54 } 55 ret: 56 return nwrote; 57 } 58 59 ssize_t FAST_FUNC xtransformer_write(transformer_state_t *xstate, const void *buf, size_t bufsize) 60 { 61 ssize_t nwrote = transformer_write(xstate, buf, bufsize); 62 if (nwrote != (ssize_t)bufsize) { 63 xfunc_die(); 64 } 65 return nwrote; 28 66 } 29 67 … … 35 73 /* block waiting for any child */ 36 74 if (wait(&status) < 0) 75 //FIXME: check EINTR? 37 76 return; /* probably there are no children */ 38 77 goto check_status; … … 42 81 for (;;) { 43 82 if (wait_any_nohang(&status) < 0) 83 //FIXME: check EINTR? 44 84 /* wait failed?! I'm confused... */ 45 85 return; 46 86 check_status: 47 if (WIFEXITED(status) && WEXITSTATUS(status) == 0) 87 /*if (WIFEXITED(status) && WEXITSTATUS(status) == 0)*/ 88 /* On Linux, the above can be checked simply as: */ 89 if (status == 0) 48 90 /* this child exited with 0 */ 49 91 continue; 50 /* Cannot happen? 51 if (!WIFSIGNALED(status) && !WIFEXITED(status)) ???; */ 92 /* Cannot happen: 93 if (!WIFSIGNALED(status) && !WIFEXITED(status)) ???; 94 */ 52 95 bb_got_signal = 1; 53 96 } … … 56 99 /* transformer(), more than meets the eye */ 57 100 #if BB_MMU 58 void FAST_FUNC open_transformer(int fd,59 int check_signature,60 IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_ aux_data_t *aux, int src_fd, int dst_fd)101 void FAST_FUNC fork_transformer(int fd, 102 int signature_skipped, 103 IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate) 61 104 ) 62 105 #else 63 void FAST_FUNC open_transformer(int fd, const char *transform_prog)106 void FAST_FUNC fork_transformer(int fd, const char *transform_prog) 64 107 #endif 65 108 { … … 75 118 #if BB_MMU 76 119 { 77 transformer_aux_data_t aux; 78 init_transformer_aux_data(&aux); 79 aux.check_signature = check_signature; 80 transformer(&aux, fd, fd_pipe.wr); 120 IF_DESKTOP(long long) int r; 121 transformer_state_t xstate; 122 init_transformer_state(&xstate); 123 xstate.signature_skipped = signature_skipped; 124 xstate.src_fd = fd; 125 xstate.dst_fd = fd_pipe.wr; 126 r = transformer(&xstate); 81 127 if (ENABLE_FEATURE_CLEAN_UP) { 82 128 close(fd_pipe.wr); /* send EOF */ … … 84 130 } 85 131 /* must be _exit! bug was actually seen here */ 86 _exit( EXIT_SUCCESS);132 _exit(/*error if:*/ r < 0); 87 133 } 88 134 #else … … 113 159 * thus we can't guess the format from filename's extension. 114 160 */ 115 int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)161 static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_compressed) 116 162 { 117 163 union { … … 120 166 uint32_t b32[1]; 121 167 } magic; 122 int offset = -2; 123 USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_aux_data_t *aux, int src_fd, int dst_fd);) 124 USE_FOR_NOMMU(const char *xformer_prog;) 168 transformer_state_t *xstate; 169 170 xstate = xzalloc(sizeof(*xstate)); 171 xstate->src_fd = fd; 172 xstate->signature_skipped = 2; 125 173 126 174 /* .gz and .bz2 both have 2-byte signature, and their … … 130 178 && magic.b16[0] == GZIP_MAGIC 131 179 ) { 132 USE_FOR_MMU(xformer = unpack_gz_stream;) 133 USE_FOR_NOMMU(xformer_prog = "gunzip";) 180 xstate->xformer = unpack_gz_stream; 181 USE_FOR_NOMMU(xstate->xformer_prog = "gunzip";) 182 goto found_magic; 183 } 184 if (ENABLE_FEATURE_SEAMLESS_Z 185 && magic.b16[0] == COMPRESS_MAGIC 186 ) { 187 xstate->xformer = unpack_Z_stream; 188 USE_FOR_NOMMU(xstate->xformer_prog = "uncompress";) 134 189 goto found_magic; 135 190 } … … 137 192 && magic.b16[0] == BZIP2_MAGIC 138 193 ) { 139 USE_FOR_MMU(xformer = unpack_bz2_stream;)140 USE_FOR_NOMMU(x former_prog = "bunzip2";)194 xstate->xformer = unpack_bz2_stream; 195 USE_FOR_NOMMU(xstate->xformer_prog = "bunzip2";) 141 196 goto found_magic; 142 197 } … … 144 199 && magic.b16[0] == XZ_MAGIC1 145 200 ) { 146 offset = -6;201 xstate->signature_skipped = 6; 147 202 xread(fd, magic.b32, sizeof(magic.b32[0])); 148 203 if (magic.b32[0] == XZ_MAGIC2) { 149 USE_FOR_MMU(xformer = unpack_xz_stream;)150 USE_FOR_NOMMU(x former_prog = "unxz";)204 xstate->xformer = unpack_xz_stream; 205 USE_FOR_NOMMU(xstate->xformer_prog = "unxz";) 151 206 goto found_magic; 152 207 } … … 154 209 155 210 /* No known magic seen */ 156 if (fail_if_not_ detected)211 if (fail_if_not_compressed) 157 212 bb_error_msg_and_die("no gzip" 158 213 IF_FEATURE_SEAMLESS_BZ2("/bzip2") 159 214 IF_FEATURE_SEAMLESS_XZ("/xz") 160 215 " magic"); 161 xlseek(fd, offset, SEEK_CUR); 162 return 1; 216 217 /* Some callers expect this function to "consume" fd 218 * even if data is not compressed. In this case, 219 * we return a state with trivial transformer. 220 */ 221 // USE_FOR_MMU(xstate->xformer = copy_stream;) 222 // USE_FOR_NOMMU(xstate->xformer_prog = "cat";) 163 223 164 224 found_magic: 225 return xstate; 226 } 227 228 /* Used by e.g. rpm which gives us a fd without filename, 229 * thus we can't guess the format from filename's extension. 230 */ 231 int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed) 232 { 233 transformer_state_t *xstate = setup_transformer_on_fd(fd, fail_if_not_compressed); 234 235 if (!xstate || !xstate->xformer) { 236 free(xstate); 237 return 1; 238 } 239 165 240 # if BB_MMU 166 open_transformer_with_no_sig(fd,xformer);241 fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer); 167 242 # else 168 /* NOMMU version of open_transformer execs243 /* NOMMU version of fork_transformer execs 169 244 * an external unzipper that wants 170 * file position at the start of the file */ 171 xlseek(fd, offset, SEEK_CUR); 172 open_transformer_with_sig(fd, xformer, xformer_prog); 245 * file position at the start of the file. 246 */ 247 xlseek(fd, - xstate->signature_skipped, SEEK_CUR); 248 xstate->signature_skipped = 0; 249 fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog); 173 250 # endif 251 free(xstate); 174 252 return 0; 175 253 } 176 254 177 int FAST_FUNC open_zipped(const char *fname)178 { 179 char *sfx;255 static transformer_state_t *open_transformer(const char *fname, int fail_if_not_compressed) 256 { 257 transformer_state_t *xstate; 180 258 int fd; 181 259 182 260 fd = open(fname, O_RDONLY); 183 261 if (fd < 0) 184 return fd; 185 186 sfx = strrchr(fname, '.'); 187 if (sfx) { 188 sfx++; 189 if (ENABLE_FEATURE_SEAMLESS_LZMA && strcmp(sfx, "lzma") == 0) 190 /* .lzma has no header/signature, just trust it */ 191 open_transformer_with_sig(fd, unpack_lzma_stream, "unlzma"); 192 else 193 if ((ENABLE_FEATURE_SEAMLESS_GZ && strcmp(sfx, "gz") == 0) 194 || (ENABLE_FEATURE_SEAMLESS_BZ2 && strcmp(sfx, "bz2") == 0) 195 || (ENABLE_FEATURE_SEAMLESS_XZ && strcmp(sfx, "xz") == 0) 196 ) { 197 setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1); 198 } 199 } 200 262 return NULL; 263 264 if (ENABLE_FEATURE_SEAMLESS_LZMA) { 265 /* .lzma has no header/signature, can only detect it by extension */ 266 char *sfx = strrchr(fname, '.'); 267 if (sfx && strcmp(sfx+1, "lzma") == 0) { 268 xstate = xzalloc(sizeof(*xstate)); 269 xstate->src_fd = fd; 270 xstate->xformer = unpack_lzma_stream; 271 USE_FOR_NOMMU(xstate->xformer_prog = "unlzma";) 272 return xstate; 273 } 274 } 275 276 xstate = setup_transformer_on_fd(fd, fail_if_not_compressed); 277 278 return xstate; 279 } 280 281 int FAST_FUNC open_zipped(const char *fname, int fail_if_not_compressed) 282 { 283 int fd; 284 transformer_state_t *xstate; 285 286 xstate = open_transformer(fname, fail_if_not_compressed); 287 if (!xstate) 288 return -1; 289 290 fd = xstate->src_fd; 291 # if BB_MMU 292 if (xstate->xformer) { 293 fork_transformer_with_no_sig(fd, xstate->xformer); 294 } else { 295 /* the file is not compressed */ 296 xlseek(fd, - xstate->signature_skipped, SEEK_CUR); 297 xstate->signature_skipped = 0; 298 } 299 # else 300 /* NOMMU can't avoid the seek :( */ 301 xlseek(fd, - xstate->signature_skipped, SEEK_CUR); 302 xstate->signature_skipped = 0; 303 if (xstate->xformer) { 304 fork_transformer_with_sig(fd, xstate->xformer, xstate->xformer_prog); 305 } /* else: the file is not compressed */ 306 # endif 307 308 free(xstate); 201 309 return fd; 202 310 } 203 311 204 #endif /* SEAMLESS_COMPRESSION */205 206 312 void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) 207 313 { 314 # if 1 315 transformer_state_t *xstate; 316 char *image; 317 318 xstate = open_transformer(fname, /*fail_if_not_compressed:*/ 0); 319 if (!xstate) /* file open error */ 320 return NULL; 321 322 image = NULL; 323 if (xstate->xformer) { 324 /* In-memory decompression */ 325 xstate->mem_output_size_max = maxsz_p ? *maxsz_p : (size_t)(INT_MAX - 4095); 326 xstate->xformer(xstate); 327 if (xstate->mem_output_buf) { 328 image = xstate->mem_output_buf; 329 if (maxsz_p) 330 *maxsz_p = xstate->mem_output_size; 331 } 332 } else { 333 /* File is not compressed */ 334 //FIXME: avoid seek 335 xlseek(xstate->src_fd, - xstate->signature_skipped, SEEK_CUR); 336 xstate->signature_skipped = 0; 337 image = xmalloc_read(xstate->src_fd, maxsz_p); 338 } 339 340 if (!image) 341 bb_perror_msg("read error from '%s'", fname); 342 close(xstate->src_fd); 343 free(xstate); 344 return image; 345 # else 346 /* This version forks a subprocess - much more expensive */ 208 347 int fd; 209 348 char *image; 210 349 211 fd = open_zipped(fname );350 fd = open_zipped(fname, /*fail_if_not_compressed:*/ 0); 212 351 if (fd < 0) 213 352 return NULL; … … 217 356 bb_perror_msg("read error from '%s'", fname); 218 357 close(fd); 219 220 358 return image; 221 } 359 # endif 360 } 361 362 #endif /* SEAMLESS_COMPRESSION */ -
branches/3.3/mindi-busybox/archival/libarchive/unpack_ar_archive.c
r3232 r3621 13 13 14 14 xread(ar_archive->src_fd, magic, AR_MAGIC_LEN); 15 if ( strncmp(magic, AR_MAGIC, AR_MAGIC_LEN) != 0) {15 if (!is_prefixed_with(magic, AR_MAGIC)) { 16 16 bb_error_msg_and_die("invalid ar magic"); 17 17 } -
branches/3.3/mindi-busybox/archival/libarchive/unxz/README
r2725 r3621 8 8 XZ Embedded was written for use in the Linux kernel, but the code can 9 9 be easily used in other environments too, including regular userspace 10 applications. 10 applications. See userspace/xzminidec.c for an example program. 11 11 12 12 This README contains information that is useful only when the copy … … 56 56 care than just using 32-bit integer instead of 64-bit). 57 57 58 If you use GCC, try to use a recent version. For example, on x86 ,58 If you use GCC, try to use a recent version. For example, on x86-32, 59 59 xz_dec_lzma2.c compiled with GCC 3.3.6 is 15-25 % slower than when 60 60 compiled with GCC 4.3.3. … … 94 94 95 95 #define Instruction set BCJ filter endianness 96 XZ_DEC_X86 x86 or x86-64Little endian only96 XZ_DEC_X86 x86-32 or x86-64 Little endian only 97 97 XZ_DEC_POWERPC PowerPC Big endian only 98 98 XZ_DEC_IA64 Itanium (IA-64) Big or little endian -
branches/3.3/mindi-busybox/archival/libarchive/unxz/xz.h
r2725 r3621 18 18 # include <stddef.h> 19 19 # include <stdint.h> 20 #endif 21 22 #ifdef __cplusplus 23 extern "C" { 20 24 #endif 21 25 … … 71 75 * is still possible in multi-call mode by simply 72 76 * calling xz_dec_run() again. 73 * N OTE: This return value is used only if77 * Note that this return value is used only if 74 78 * XZ_DEC_ANY_CHECK was defined at build time, 75 79 * which is not used in the kernel. Unsupported … … 106 110 * 107 111 * In single-call mode, XZ_BUF_ERROR is returned only when the output buffer 108 * is too small ,or the compressed input is corrupt in a way that makes the112 * is too small or the compressed input is corrupt in a way that makes the 109 113 * decoder produce more output than the caller expected. When it is 110 114 * (relatively) clear that the compressed input is truncated, XZ_DATA_ERROR … … 208 212 * See enum xz_ret for details. 209 213 * 210 * N OTE: If an error occurs in single-call mode (return value is not211 * XZ_STREAM_END), b->in_pos and b->out_pos are not modified ,and the214 * Note that if an error occurs in single-call mode (return value is not 215 * XZ_STREAM_END), b->in_pos and b->out_pos are not modified and the 212 216 * contents of the output buffer from b->out[b->out_pos] onward are 213 217 * undefined. This is true even after XZ_BUF_ERROR, because with some filter … … 269 273 const uint8_t *buf, size_t size, uint32_t crc); 270 274 #endif 271 #endif 275 276 #ifdef __cplusplus 277 } 278 #endif 279 280 #endif -
branches/3.3/mindi-busybox/archival/libarchive/unxz/xz_dec_bcj.c
r2725 r3621 78 78 #ifdef XZ_DEC_X86 79 79 /* 80 * This is macroused to test the most significant byte of a memory address80 * This is used to test the most significant byte of a memory address 81 81 * in an x86 instruction. 82 82 */ 83 #define bcj_x86_test_msbyte(b) ((b) == 0x00 || (b) == 0xFF) 83 static inline int bcj_x86_test_msbyte(uint8_t b) 84 { 85 return b == 0x00 || b == 0xFF; 86 } 84 87 85 88 static noinline_for_stack size_t XZ_FUNC bcj_x86( … … 444 447 * in the output buffer. If everything cannot be filtered, copy it 445 448 * to temp and rewind the output buffer position accordingly. 449 * 450 * This needs to be always run when temp.size == 0 to handle a special 451 * case where the output buffer is full and the next filter has no 452 * more output coming but hasn't returned XZ_STREAM_END yet. 446 453 */ 447 if (s->temp.size < b->out_size - b->out_pos ) {454 if (s->temp.size < b->out_size - b->out_pos || s->temp.size == 0) { 448 455 out_start = b->out_pos; 449 456 memcpy(b->out + b->out_pos, s->temp.buf, s->temp.size); … … 468 475 b->out_pos -= s->temp.size; 469 476 memcpy(s->temp.buf, b->out + b->out_pos, s->temp.size); 477 478 /* 479 * If there wasn't enough input to the next filter to fill 480 * the output buffer with unfiltered data, there's no point 481 * to try decoding more data to temp. 482 */ 483 if (b->out_pos + s->temp.size < b->out_size) 484 return XZ_OK; 470 485 } 471 486 472 487 /* 473 * If we have unfiltered data in temp, try to fill by decoding more 474 * data from the next filter. Apply the BCJ filter on temp. Then we 475 * hopefully can fill the actual output buffer by copying filtered 476 * data from temp. A mix of filtered and unfiltered data may be left 477 * in temp; it will be taken care on the next call to this function. 488 * We have unfiltered data in temp. If the output buffer isn't full 489 * yet, try to fill the temp buffer by decoding more data from the 490 * next filter. Apply the BCJ filter on temp. Then we hopefully can 491 * fill the actual output buffer by copying filtered data from temp. 492 * A mix of filtered and unfiltered data may be left in temp; it will 493 * be taken care on the next call to this function. 478 494 */ 479 if ( s->temp.size > 0) {495 if (b->out_pos < b->out_size) { 480 496 /* Make b->out{,_pos,_size} temporarily point to s->temp. */ 481 497 s->out = b->out; -
branches/3.3/mindi-busybox/archival/libarchive/unxz/xz_dec_lzma2.c
r2725 r3621 408 408 b->out_pos += copy_size; 409 409 b->in_pos += copy_size; 410 411 410 } 412 411 } … … 973 972 tmp = b->in[b->in_pos++]; 974 973 974 if (tmp == 0x00) 975 return XZ_STREAM_END; 976 975 977 if (tmp >= 0xE0 || tmp == 0x01) { 976 978 s->lzma2.need_props = true; … … 994 996 s->lzma2.next_sequence 995 997 = SEQ_PROPERTIES; 996 997 998 } else if (s->lzma2.need_props) { 998 999 return XZ_DATA_ERROR; 999 1000 1000 } else { 1001 1001 s->lzma2.next_sequence … … 1005 1005 } 1006 1006 } else { 1007 if (tmp == 0x00)1008 return XZ_STREAM_END;1009 1010 1007 if (tmp > 0x02) 1011 1008 return XZ_DATA_ERROR; … … 1082 1079 rc_reset(&s->rc); 1083 1080 s->lzma2.sequence = SEQ_CONTROL; 1084 1085 1081 } else if (b->out_pos == b->out_size 1086 1082 || (b->in_pos == b->in_size -
branches/3.3/mindi-busybox/archival/libarchive/unxz/xz_dec_stream.c
r2725 r3621 354 354 355 355 s->pos += 8; 356 357 356 } while (s->pos < 32); 358 357 … … 754 753 b->out_pos = out_start; 755 754 } 756 757 755 } else if (ret == XZ_OK && in_start == b->in_pos 758 756 && out_start == b->out_pos) { -
branches/3.3/mindi-busybox/archival/libarchive/unxz/xz_stream.h
r2725 r3621 26 26 #define STREAM_HEADER_SIZE 12 27 27 28 #define HEADER_MAGIC "\3757zXZ \0"28 #define HEADER_MAGIC "\3757zXZ" 29 29 #define HEADER_MAGIC_SIZE 6 30 30 … … 33 33 34 34 /* 35 * Variable-length integer can hold a 63-bit unsigned integer, or a special 36 * value to indicate that the value is unknown. 35 * Variable-length integer can hold a 63-bit unsigned integer or a special 36 * value indicating that the value is unknown. 37 * 38 * Experimental: vli_type can be defined to uint32_t to save a few bytes 39 * in code size (no effect on speed). Doing so limits the uncompressed and 40 * compressed size of the file to less than 256 MiB and may also weaken 41 * error detection slightly. 37 42 */ 38 43 typedef uint64_t vli_type;
Note:
See TracChangeset
for help on using the changeset viewer.