aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-06-29 17:00:22 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2013-06-29 17:00:22 +0200
commite73f3c1d3d83699b723251f7e6a981021ce75475 (patch)
treee0272460fb0dbbe33412a09534c088634fd3ed24 /arch
parent64406a92a054f884747553011d4529103e2900e4 (diff)
downloadbusybox-w32-1_21_1.tar.gz
busybox-w32-1_21_1.tar.bz2
busybox-w32-1_21_1.zip
Apply post-1.21.0 patches, bump version to 1.21.11_21_1
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r--archival/libarchive/decompress_unxz.c47
1 files changed, 38 insertions, 9 deletions
diff --git a/archival/libarchive/decompress_unxz.c b/archival/libarchive/decompress_unxz.c
index 79b48a152..986b7b191 100644
--- a/archival/libarchive/decompress_unxz.c
+++ b/archival/libarchive/decompress_unxz.c
@@ -30,8 +30,8 @@ static uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
30/* We use arch-optimized unaligned accessors */ 30/* We use arch-optimized unaligned accessors */
31#define get_unaligned_le32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_LE32(v); }) 31#define get_unaligned_le32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_LE32(v); })
32#define get_unaligned_be32(buf) ({ uint32_t v; move_from_unaligned32(v, buf); SWAP_BE32(v); }) 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_unaligned16(buf, SWAP_LE32(val)) 33#define put_unaligned_le32(val, buf) move_to_unaligned32(buf, SWAP_LE32(val))
34#define put_unaligned_be32(val, buf) move_to_unaligned16(buf, SWAP_BE32(val)) 34#define put_unaligned_be32(val, buf) move_to_unaligned32(buf, SWAP_BE32(val))
35 35
36#include "unxz/xz_dec_bcj.c" 36#include "unxz/xz_dec_bcj.c"
37#include "unxz/xz_dec_lzma2.c" 37#include "unxz/xz_dec_lzma2.c"
@@ -40,6 +40,7 @@ static uint32_t xz_crc32(const uint8_t *buf, size_t size, uint32_t crc)
40IF_DESKTOP(long long) int FAST_FUNC 40IF_DESKTOP(long long) int FAST_FUNC
41unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd) 41unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
42{ 42{
43 enum xz_ret xz_result;
43 struct xz_buf iobuf; 44 struct xz_buf iobuf;
44 struct xz_dec *state; 45 struct xz_dec *state;
45 unsigned char *membuf; 46 unsigned char *membuf;
@@ -63,9 +64,8 @@ unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
63 /* Limit memory usage to about 64 MiB. */ 64 /* Limit memory usage to about 64 MiB. */
64 state = xz_dec_init(XZ_DYNALLOC, 64*1024*1024); 65 state = xz_dec_init(XZ_DYNALLOC, 64*1024*1024);
65 66
67 xz_result = X_OK;
66 while (1) { 68 while (1) {
67 enum xz_ret r;
68
69 if (iobuf.in_pos == iobuf.in_size) { 69 if (iobuf.in_pos == iobuf.in_size) {
70 int rd = safe_read(src_fd, membuf, BUFSIZ); 70 int rd = safe_read(src_fd, membuf, BUFSIZ);
71 if (rd < 0) { 71 if (rd < 0) {
@@ -73,28 +73,57 @@ unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
73 total = -1; 73 total = -1;
74 break; 74 break;
75 } 75 }
76 if (rd == 0 && xz_result == XZ_STREAM_END)
77 break;
76 iobuf.in_size = rd; 78 iobuf.in_size = rd;
77 iobuf.in_pos = 0; 79 iobuf.in_pos = 0;
78 } 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:
79// bb_error_msg(">in pos:%d size:%d out pos:%d size:%d", 101// bb_error_msg(">in pos:%d size:%d out pos:%d size:%d",
80// iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size); 102// iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size);
81 r = xz_dec_run(state, &iobuf); 103 xz_result = xz_dec_run(state, &iobuf);
82// bb_error_msg("<in pos:%d size:%d out pos:%d size:%d r:%d", 104// bb_error_msg("<in pos:%d size:%d out pos:%d size:%d r:%d",
83// 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);
84 if (iobuf.out_pos) { 106 if (iobuf.out_pos) {
85 xwrite(dst_fd, iobuf.out, iobuf.out_pos); 107 xwrite(dst_fd, iobuf.out, iobuf.out_pos);
86 IF_DESKTOP(total += iobuf.out_pos;) 108 IF_DESKTOP(total += iobuf.out_pos;)
87 iobuf.out_pos = 0; 109 iobuf.out_pos = 0;
88 } 110 }
89 if (r == XZ_STREAM_END) { 111 if (xz_result == XZ_STREAM_END) {
90 break; 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;
91 } 119 }
92 if (r != XZ_OK && r != XZ_UNSUPPORTED_CHECK) { 120 if (xz_result != XZ_OK && xz_result != XZ_UNSUPPORTED_CHECK) {
93 bb_error_msg("corrupted data"); 121 bb_error_msg("corrupted data");
94 total = -1; 122 total = -1;
95 break; 123 break;
96 } 124 }
97 } 125 }
126
98 xz_dec_end(state); 127 xz_dec_end(state);
99 free(membuf); 128 free(membuf);
100 129