Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/archival/libarchive/decompress_unxz.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/archival/libarchive/decompress_unxz.c
r2725 r3232 11 11 */ 12 12 #include "libbb.h" 13 #include " archive.h"13 #include "bb_archive.h" 14 14 15 15 #define XZ_FUNC FAST_FUNC … … 31 31 #define get_unaligned_le32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_LE32(v); }) 32 32 #define get_unaligned_be32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_BE32(v); }) 33 #define put_unaligned_le32(val, buf) move_to_unaligned 16(buf, SWAP_LE32(val))34 #define put_unaligned_be32(val, buf) move_to_unaligned 16(buf, SWAP_BE32(val))33 #define put_unaligned_le32(val, buf) move_to_unaligned32(buf, SWAP_LE32(val)) 34 #define put_unaligned_be32(val, buf) move_to_unaligned32(buf, SWAP_BE32(val)) 35 35 36 36 #include "unxz/xz_dec_bcj.c" … … 39 39 40 40 IF_DESKTOP(long long) int FAST_FUNC 41 unpack_xz_stream( int src_fd, int dst_fd)41 unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) 42 42 { 43 enum xz_ret xz_result; 43 44 struct xz_buf iobuf; 44 45 struct xz_dec *state; … … 50 51 51 52 memset(&iobuf, 0, sizeof(iobuf)); 52 /* Preload XZ file signature */ 53 membuf = (void*) strcpy(xmalloc(2 * BUFSIZ), HEADER_MAGIC); 53 membuf = xmalloc(2 * BUFSIZ); 54 54 iobuf.in = membuf; 55 iobuf.in_size = HEADER_MAGIC_SIZE;56 55 iobuf.out = membuf + BUFSIZ; 57 56 iobuf.out_size = BUFSIZ; 57 58 if (!aux || aux->check_signature == 0) { 59 /* Preload XZ file signature */ 60 strcpy((char*)membuf, HEADER_MAGIC); 61 iobuf.in_size = HEADER_MAGIC_SIZE; 62 } /* else: let xz code read & check it */ 58 63 59 64 /* Limit memory usage to about 64 MiB. */ 60 65 state = xz_dec_init(XZ_DYNALLOC, 64*1024*1024); 61 66 67 xz_result = X_OK; 62 68 while (1) { 63 enum xz_ret r;64 65 69 if (iobuf.in_pos == iobuf.in_size) { 66 70 int rd = safe_read(src_fd, membuf, BUFSIZ); … … 70 74 break; 71 75 } 76 if (rd == 0 && xz_result == XZ_STREAM_END) 77 break; 72 78 iobuf.in_size = rd; 73 79 iobuf.in_pos = 0; 74 80 } 81 if (xz_result == XZ_STREAM_END) { 82 /* 83 * Try to start decoding next concatenated stream. 84 * Stream padding must always be a multiple of four 85 * bytes to preserve four-byte alignment. To keep the 86 * code slightly smaller, we aren't as strict here as 87 * the .xz spec requires. We just skip all zero-bytes 88 * without checking the alignment and thus can accept 89 * files that aren't valid, e.g. the XZ utils test 90 * files bad-0pad-empty.xz and bad-0catpad-empty.xz. 91 */ 92 do { 93 if (membuf[iobuf.in_pos] != 0) { 94 xz_dec_reset(state); 95 goto do_run; 96 } 97 iobuf.in_pos++; 98 } while (iobuf.in_pos < iobuf.in_size); 99 } 100 do_run: 75 101 // bb_error_msg(">in pos:%d size:%d out pos:%d size:%d", 76 102 // iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size); 77 r= xz_dec_run(state, &iobuf);103 xz_result = xz_dec_run(state, &iobuf); 78 104 // bb_error_msg("<in pos:%d size:%d out pos:%d size:%d r:%d", 79 // iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, r);105 // iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, xz_result); 80 106 if (iobuf.out_pos) { 81 107 xwrite(dst_fd, iobuf.out, iobuf.out_pos); … … 83 109 iobuf.out_pos = 0; 84 110 } 85 if (r == XZ_STREAM_END) { 86 break; 111 if (xz_result == XZ_STREAM_END) { 112 /* 113 * Can just "break;" here, if not for concatenated 114 * .xz streams. 115 * Checking for padding may require buffer 116 * replenishment. Can't do it here. 117 */ 118 continue; 87 119 } 88 if ( r != XZ_OK && r!= XZ_UNSUPPORTED_CHECK) {120 if (xz_result != XZ_OK && xz_result != XZ_UNSUPPORTED_CHECK) { 89 121 bb_error_msg("corrupted data"); 90 122 total = -1; … … 92 124 } 93 125 } 126 94 127 xz_dec_end(state); 95 128 free(membuf);
Note:
See TracChangeset
for help on using the changeset viewer.