rev |
line source |
pascal@15734
|
1 --- busybox-1.21.0/archival/libarchive/decompress_unxz.c
|
pascal@15734
|
2 +++ busybox-1.21.0/archival/libarchive/decompress_unxz.c
|
pascal@15734
|
3 @@ -40,6 +40,7 @@ static uint32_t xz_crc32(const uint8_t *
|
pascal@15734
|
4 IF_DESKTOP(long long) int FAST_FUNC
|
pascal@15734
|
5 unpack_xz_stream(transformer_aux_data_t *aux, int src_fd, int dst_fd)
|
pascal@15734
|
6 {
|
pascal@15734
|
7 + enum xz_ret xz_result;
|
pascal@15734
|
8 struct xz_buf iobuf;
|
pascal@15734
|
9 struct xz_dec *state;
|
pascal@15734
|
10 unsigned char *membuf;
|
pascal@15734
|
11 @@ -63,9 +64,8 @@ unpack_xz_stream(transformer_aux_data_t
|
pascal@15734
|
12 /* Limit memory usage to about 64 MiB. */
|
pascal@15734
|
13 state = xz_dec_init(XZ_DYNALLOC, 64*1024*1024);
|
pascal@15734
|
14
|
pascal@15734
|
15 + xz_result = X_OK;
|
pascal@15734
|
16 while (1) {
|
pascal@15734
|
17 - enum xz_ret r;
|
pascal@15734
|
18 -
|
pascal@15734
|
19 if (iobuf.in_pos == iobuf.in_size) {
|
pascal@15734
|
20 int rd = safe_read(src_fd, membuf, BUFSIZ);
|
pascal@15734
|
21 if (rd < 0) {
|
pascal@15734
|
22 @@ -73,28 +73,57 @@ unpack_xz_stream(transformer_aux_data_t
|
pascal@15734
|
23 total = -1;
|
pascal@15734
|
24 break;
|
pascal@15734
|
25 }
|
pascal@15734
|
26 + if (rd == 0 && xz_result == XZ_STREAM_END)
|
pascal@15734
|
27 + break;
|
pascal@15734
|
28 iobuf.in_size = rd;
|
pascal@15734
|
29 iobuf.in_pos = 0;
|
pascal@15734
|
30 }
|
pascal@15734
|
31 + if (xz_result == XZ_STREAM_END) {
|
pascal@15734
|
32 + /*
|
pascal@15734
|
33 + * Try to start decoding next concatenated stream.
|
pascal@15734
|
34 + * Stream padding must always be a multiple of four
|
pascal@15734
|
35 + * bytes to preserve four-byte alignment. To keep the
|
pascal@15734
|
36 + * code slightly smaller, we aren't as strict here as
|
pascal@15734
|
37 + * the .xz spec requires. We just skip all zero-bytes
|
pascal@15734
|
38 + * without checking the alignment and thus can accept
|
pascal@15734
|
39 + * files that aren't valid, e.g. the XZ utils test
|
pascal@15734
|
40 + * files bad-0pad-empty.xz and bad-0catpad-empty.xz.
|
pascal@15734
|
41 + */
|
pascal@15734
|
42 + do {
|
pascal@15734
|
43 + if (membuf[iobuf.in_pos] != 0) {
|
pascal@15734
|
44 + xz_dec_reset(state);
|
pascal@15734
|
45 + goto do_run;
|
pascal@15734
|
46 + }
|
pascal@15734
|
47 + iobuf.in_pos++;
|
pascal@15734
|
48 + } while (iobuf.in_pos < iobuf.in_size);
|
pascal@15734
|
49 + }
|
pascal@15734
|
50 + do_run:
|
pascal@15734
|
51 // bb_error_msg(">in pos:%d size:%d out pos:%d size:%d",
|
pascal@15734
|
52 // iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size);
|
pascal@15734
|
53 - r = xz_dec_run(state, &iobuf);
|
pascal@15734
|
54 + xz_result = xz_dec_run(state, &iobuf);
|
pascal@15734
|
55 // bb_error_msg("<in pos:%d size:%d out pos:%d size:%d r:%d",
|
pascal@15734
|
56 -// iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, r);
|
pascal@15734
|
57 +// iobuf.in_pos, iobuf.in_size, iobuf.out_pos, iobuf.out_size, xz_result);
|
pascal@15734
|
58 if (iobuf.out_pos) {
|
pascal@15734
|
59 xwrite(dst_fd, iobuf.out, iobuf.out_pos);
|
pascal@15734
|
60 IF_DESKTOP(total += iobuf.out_pos;)
|
pascal@15734
|
61 iobuf.out_pos = 0;
|
pascal@15734
|
62 }
|
pascal@15734
|
63 - if (r == XZ_STREAM_END) {
|
pascal@15734
|
64 - break;
|
pascal@15734
|
65 + if (xz_result == XZ_STREAM_END) {
|
pascal@15734
|
66 + /*
|
pascal@15734
|
67 + * Can just "break;" here, if not for concatenated
|
pascal@15734
|
68 + * .xz streams.
|
pascal@15734
|
69 + * Checking for padding may require buffer
|
pascal@15734
|
70 + * replenishment. Can't do it here.
|
pascal@15734
|
71 + */
|
pascal@15734
|
72 + continue;
|
pascal@15734
|
73 }
|
pascal@15734
|
74 - if (r != XZ_OK && r != XZ_UNSUPPORTED_CHECK) {
|
pascal@15734
|
75 + if (xz_result != XZ_OK && xz_result != XZ_UNSUPPORTED_CHECK) {
|
pascal@15734
|
76 bb_error_msg("corrupted data");
|
pascal@15734
|
77 total = -1;
|
pascal@15734
|
78 break;
|
pascal@15734
|
79 }
|
pascal@15734
|
80 }
|
pascal@15734
|
81 +
|
pascal@15734
|
82 xz_dec_end(state);
|
pascal@15734
|
83 free(membuf);
|
pascal@15734
|
84
|