diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2019-10-11 14:11:44 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2019-10-11 14:11:44 +0200 |
commit | 42f454b13b8d972e85acd7f046065ec69af4d206 (patch) | |
tree | 2cc09f3970a5115bee0fccda3c558a1e9211660f | |
parent | 7011eca83afc313098f9869eea36742d4506bc02 (diff) | |
download | busybox-w32-42f454b13b8d972e85acd7f046065ec69af4d206.tar.gz busybox-w32-42f454b13b8d972e85acd7f046065ec69af4d206.tar.bz2 busybox-w32-42f454b13b8d972e85acd7f046065ec69af4d206.zip |
dpkg-deb: work around bogus error message when working with XZ compressed packages
function old new delta
unpack_xz_stream 2309 2317 +8
bb_full_fd_action 464 472 +8
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | archival/libarchive/decompress_unxz.c | 20 | ||||
-rw-r--r-- | archival/libarchive/unxz/xz_stream.h | 2 | ||||
-rw-r--r-- | libbb/copyfd.c | 13 |
3 files changed, 28 insertions, 7 deletions
diff --git a/archival/libarchive/decompress_unxz.c b/archival/libarchive/decompress_unxz.c index f03341384..3dd9bbf49 100644 --- a/archival/libarchive/decompress_unxz.c +++ b/archival/libarchive/decompress_unxz.c | |||
@@ -96,6 +96,24 @@ unpack_xz_stream(transformer_state_t *xstate) | |||
96 | */ | 96 | */ |
97 | do { | 97 | do { |
98 | if (membuf[iobuf.in_pos] != 0) { | 98 | if (membuf[iobuf.in_pos] != 0) { |
99 | /* There is more data, but is it XZ data? | ||
100 | * Example: dpkg-deb -f busybox_1.30.1-4_amd64.deb | ||
101 | * reads control.tar.xz "control" file | ||
102 | * inside the ar archive, but tar.xz | ||
103 | * extraction code reaches end of xz data, | ||
104 | * reached this code and reads the beginning | ||
105 | * of data.tar.xz's ar header, which isn't xz data, | ||
106 | * and prints "corrupted data". | ||
107 | * The correct solution is to not read | ||
108 | * past nested archive (to simulate EOF). | ||
109 | * This is a workaround: | ||
110 | */ | ||
111 | if (membuf[iobuf.in_pos] != 0xfd) { | ||
112 | /* It's definitely not a xz signature | ||
113 | * (which is 0xfd,"7zXZ",0x00). | ||
114 | */ | ||
115 | goto end; | ||
116 | } | ||
99 | xz_dec_reset(state); | 117 | xz_dec_reset(state); |
100 | goto do_run; | 118 | goto do_run; |
101 | } | 119 | } |
@@ -128,7 +146,7 @@ unpack_xz_stream(transformer_state_t *xstate) | |||
128 | break; | 146 | break; |
129 | } | 147 | } |
130 | } | 148 | } |
131 | 149 | end: | |
132 | xz_dec_end(state); | 150 | xz_dec_end(state); |
133 | free(membuf); | 151 | free(membuf); |
134 | 152 | ||
diff --git a/archival/libarchive/unxz/xz_stream.h b/archival/libarchive/unxz/xz_stream.h index 66cb5a705..45056e42c 100644 --- a/archival/libarchive/unxz/xz_stream.h +++ b/archival/libarchive/unxz/xz_stream.h | |||
@@ -25,7 +25,7 @@ | |||
25 | 25 | ||
26 | #define STREAM_HEADER_SIZE 12 | 26 | #define STREAM_HEADER_SIZE 12 |
27 | 27 | ||
28 | #define HEADER_MAGIC "\3757zXZ" | 28 | #define HEADER_MAGIC "\375""7zXZ" |
29 | #define HEADER_MAGIC_SIZE 6 | 29 | #define HEADER_MAGIC_SIZE 6 |
30 | 30 | ||
31 | #define FOOTER_MAGIC "YZ" | 31 | #define FOOTER_MAGIC "YZ" |
diff --git a/libbb/copyfd.c b/libbb/copyfd.c index ae5c26999..d41fd10f0 100644 --- a/libbb/copyfd.c +++ b/libbb/copyfd.c | |||
@@ -18,7 +18,7 @@ | |||
18 | * was seen to cause largish delays when user tries to ^C a file copy. | 18 | * was seen to cause largish delays when user tries to ^C a file copy. |
19 | * Let's use a saner size. | 19 | * Let's use a saner size. |
20 | * Note: needs to be >= max(CONFIG_FEATURE_COPYBUF_KB), | 20 | * Note: needs to be >= max(CONFIG_FEATURE_COPYBUF_KB), |
21 | * or else "copy to eof" code will use neddlesly short reads. | 21 | * or else "copy to eof" code will use needlesly short reads. |
22 | */ | 22 | */ |
23 | #define SENDFILE_BIGBUF (16*1024*1024) | 23 | #define SENDFILE_BIGBUF (16*1024*1024) |
24 | 24 | ||
@@ -60,10 +60,13 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size) | |||
60 | ssize_t rd; | 60 | ssize_t rd; |
61 | 61 | ||
62 | if (sendfile_sz) { | 62 | if (sendfile_sz) { |
63 | rd = sendfile(dst_fd, src_fd, NULL, | 63 | /* dst_fd == -1 is a fake, else... */ |
64 | size > sendfile_sz ? sendfile_sz : size); | 64 | if (dst_fd >= 0) { |
65 | if (rd >= 0) | 65 | rd = sendfile(dst_fd, src_fd, NULL, |
66 | goto read_ok; | 66 | size > sendfile_sz ? sendfile_sz : size); |
67 | if (rd >= 0) | ||
68 | goto read_ok; | ||
69 | } | ||
67 | sendfile_sz = 0; /* do not try sendfile anymore */ | 70 | sendfile_sz = 0; /* do not try sendfile anymore */ |
68 | } | 71 | } |
69 | #if CONFIG_FEATURE_COPYBUF_KB > 4 | 72 | #if CONFIG_FEATURE_COPYBUF_KB > 4 |