aboutsummaryrefslogtreecommitdiff
path: root/archival/libarchive
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2016-07-07 14:28:08 +0100
committerRon Yorston <rmy@pobox.com>2016-07-07 14:58:55 +0100
commit613f46218c53c8cabdbf0435653e74e0e0e91e1c (patch)
treeca06a7e7a3e4c861441acb4ea20648d7827fa6ae /archival/libarchive
parenta0c61c9492723dd31681f878f9c68c92817a476d (diff)
parent237bedd499c58034a1355484d6d4d906f0180308 (diff)
downloadbusybox-w32-613f46218c53c8cabdbf0435653e74e0e0e91e1c.tar.gz
busybox-w32-613f46218c53c8cabdbf0435653e74e0e0e91e1c.tar.bz2
busybox-w32-613f46218c53c8cabdbf0435653e74e0e0e91e1c.zip
Merge branch 'busybox' into merge
Diffstat (limited to 'archival/libarchive')
-rw-r--r--archival/libarchive/decompress_gunzip.c4
-rw-r--r--archival/libarchive/decompress_unxz.c2
-rw-r--r--archival/libarchive/get_header_tar.c23
-rw-r--r--archival/libarchive/open_transformer.c55
4 files changed, 48 insertions, 36 deletions
diff --git a/archival/libarchive/decompress_gunzip.c b/archival/libarchive/decompress_gunzip.c
index 94dbd7a95..74d364379 100644
--- a/archival/libarchive/decompress_gunzip.c
+++ b/archival/libarchive/decompress_gunzip.c
@@ -1207,7 +1207,7 @@ unpack_gz_stream(transformer_state_t *xstate)
1207 if (check_signature16(xstate, GZIP_MAGIC)) 1207 if (check_signature16(xstate, GZIP_MAGIC))
1208 return -1; 1208 return -1;
1209#else 1209#else
1210 if (xstate->check_signature) { 1210 if (!xstate->signature_skipped) {
1211 uint16_t magic2; 1211 uint16_t magic2;
1212 1212
1213 if (full_read(xstate->src_fd, &magic2, 2) != 2) { 1213 if (full_read(xstate->src_fd, &magic2, 2) != 2) {
@@ -1216,7 +1216,7 @@ unpack_gz_stream(transformer_state_t *xstate)
1216 return -1; 1216 return -1;
1217 } 1217 }
1218 if (magic2 == COMPRESS_MAGIC) { 1218 if (magic2 == COMPRESS_MAGIC) {
1219 xstate->check_signature = 0; 1219 xstate->signature_skipped = 2;
1220 return unpack_Z_stream(xstate); 1220 return unpack_Z_stream(xstate);
1221 } 1221 }
1222 if (magic2 != GZIP_MAGIC) 1222 if (magic2 != GZIP_MAGIC)
diff --git a/archival/libarchive/decompress_unxz.c b/archival/libarchive/decompress_unxz.c
index 1f408abfd..cd32cc745 100644
--- a/archival/libarchive/decompress_unxz.c
+++ b/archival/libarchive/decompress_unxz.c
@@ -55,7 +55,7 @@ unpack_xz_stream(transformer_state_t *xstate)
55 iobuf.out = membuf + BUFSIZ; 55 iobuf.out = membuf + BUFSIZ;
56 iobuf.out_size = BUFSIZ; 56 iobuf.out_size = BUFSIZ;
57 57
58 if (!xstate || xstate->check_signature == 0) { 58 if (!xstate || xstate->signature_skipped) {
59 /* Preload XZ file signature */ 59 /* Preload XZ file signature */
60 strcpy((char*)membuf, HEADER_MAGIC); 60 strcpy((char*)membuf, HEADER_MAGIC);
61 iobuf.in_size = HEADER_MAGIC_SIZE; 61 iobuf.in_size = HEADER_MAGIC_SIZE;
diff --git a/archival/libarchive/get_header_tar.c b/archival/libarchive/get_header_tar.c
index ac2be726f..ea91a883e 100644
--- a/archival/libarchive/get_header_tar.c
+++ b/archival/libarchive/get_header_tar.c
@@ -60,13 +60,21 @@ static unsigned long long getOctal(char *str, int len)
60} 60}
61#define GET_OCTAL(a) getOctal((a), sizeof(a)) 61#define GET_OCTAL(a) getOctal((a), sizeof(a))
62 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
63/* "global" is 0 or 1 */ 68/* "global" is 0 or 1 */
64static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int global) 69static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int global)
65{ 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);
66 char *buf, *p; 76 char *buf, *p;
67 unsigned blk_sz;
68 77
69 blk_sz = (sz + 511) & (~511);
70 p = buf = xmalloc(blk_sz + 1); 78 p = buf = xmalloc(blk_sz + 1);
71 xread(archive_handle->src_fd, buf, blk_sz); 79 xread(archive_handle->src_fd, buf, blk_sz);
72 archive_handle->offset += blk_sz; 80 archive_handle->offset += blk_sz;
@@ -104,30 +112,31 @@ static void process_pax_hdr(archive_handle_t *archive_handle, unsigned sz, int g
104 p[-1] = '\0'; 112 p[-1] = '\0';
105 value = end + 1; 113 value = end + 1;
106 114
107#if ENABLE_FEATURE_TAR_GNU_EXTENSIONS 115# if ENABLE_FEATURE_TAR_GNU_EXTENSIONS
108 if (!global && is_prefixed_with(value, "path=")) { 116 if (!global && is_prefixed_with(value, "path=")) {
109 value += sizeof("path=") - 1; 117 value += sizeof("path=") - 1;
110 free(archive_handle->tar__longname); 118 free(archive_handle->tar__longname);
111 archive_handle->tar__longname = xstrdup(value); 119 archive_handle->tar__longname = xstrdup(value);
112 continue; 120 continue;
113 } 121 }
114#endif 122# endif
115 123
116#if ENABLE_FEATURE_TAR_SELINUX 124# if ENABLE_FEATURE_TAR_SELINUX
117 /* Scan for SELinux contexts, via "RHT.security.selinux" keyword. 125 /* Scan for SELinux contexts, via "RHT.security.selinux" keyword.
118 * This is what Red Hat's patched version of tar uses. 126 * This is what Red Hat's patched version of tar uses.
119 */ 127 */
120# define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux" 128# define SELINUX_CONTEXT_KEYWORD "RHT.security.selinux"
121 if (is_prefixed_with(value, SELINUX_CONTEXT_KEYWORD"=")) { 129 if (is_prefixed_with(value, SELINUX_CONTEXT_KEYWORD"=")) {
122 value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1; 130 value += sizeof(SELINUX_CONTEXT_KEYWORD"=") - 1;
123 free(archive_handle->tar__sctx[global]); 131 free(archive_handle->tar__sctx[global]);
124 archive_handle->tar__sctx[global] = xstrdup(value); 132 archive_handle->tar__sctx[global] = xstrdup(value);
125 continue; 133 continue;
126 } 134 }
127#endif 135# endif
128 } 136 }
129 137
130 free(buf); 138 free(buf);
139#endif
131} 140}
132 141
133char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) 142char FAST_FUNC get_header_tar(archive_handle_t *archive_handle)
diff --git a/archival/libarchive/open_transformer.c b/archival/libarchive/open_transformer.c
index 7b18aeff4..641256787 100644
--- a/archival/libarchive/open_transformer.c
+++ b/archival/libarchive/open_transformer.c
@@ -13,16 +13,13 @@ void FAST_FUNC init_transformer_state(transformer_state_t *xstate)
13 13
14int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16) 14int FAST_FUNC check_signature16(transformer_state_t *xstate, unsigned magic16)
15{ 15{
16 if (xstate->check_signature) { 16 if (!xstate->signature_skipped) {
17 uint16_t magic2; 17 uint16_t magic2;
18 if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) { 18 if (full_read(xstate->src_fd, &magic2, 2) != 2 || magic2 != magic16) {
19 bb_error_msg("invalid magic"); 19 bb_error_msg("invalid magic");
20#if 0 /* possible future extension */
21 if (xstate->check_signature > 1)
22 xfunc_die();
23#endif
24 return -1; 20 return -1;
25 } 21 }
22 xstate->signature_skipped = 2;
26 } 23 }
27 return 0; 24 return 0;
28} 25}
@@ -103,7 +100,7 @@ void check_errors_in_children(int signo)
103/* transformer(), more than meets the eye */ 100/* transformer(), more than meets the eye */
104#if BB_MMU 101#if BB_MMU
105void FAST_FUNC fork_transformer(int fd, 102void FAST_FUNC fork_transformer(int fd,
106 int check_signature, 103 int signature_skipped,
107 IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate) 104 IF_DESKTOP(long long) int FAST_FUNC (*transformer)(transformer_state_t *xstate)
108) 105)
109#else 106#else
@@ -124,7 +121,7 @@ void FAST_FUNC fork_transformer(int fd, const char *transform_prog)
124 IF_DESKTOP(long long) int r; 121 IF_DESKTOP(long long) int r;
125 transformer_state_t xstate; 122 transformer_state_t xstate;
126 init_transformer_state(&xstate); 123 init_transformer_state(&xstate);
127 xstate.check_signature = check_signature; 124 xstate.signature_skipped = signature_skipped;
128 xstate.src_fd = fd; 125 xstate.src_fd = fd;
129 xstate.dst_fd = fd_pipe.wr; 126 xstate.dst_fd = fd_pipe.wr;
130 r = transformer(&xstate); 127 r = transformer(&xstate);
@@ -194,12 +191,11 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
194 uint16_t b16[2]; 191 uint16_t b16[2];
195 uint32_t b32[1]; 192 uint32_t b32[1];
196 } magic; 193 } magic;
197 int offset;
198 transformer_state_t *xstate; 194 transformer_state_t *xstate;
199 195
200 offset = -2;
201 xstate = xzalloc(sizeof(*xstate)); 196 xstate = xzalloc(sizeof(*xstate));
202 xstate->src_fd = fd; 197 xstate->src_fd = fd;
198 xstate->signature_skipped = 2;
203 199
204 /* .gz and .bz2 both have 2-byte signature, and their 200 /* .gz and .bz2 both have 2-byte signature, and their
205 * unpack_XXX_stream wants this header skipped. */ 201 * unpack_XXX_stream wants this header skipped. */
@@ -228,7 +224,7 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
228 if (ENABLE_FEATURE_SEAMLESS_XZ 224 if (ENABLE_FEATURE_SEAMLESS_XZ
229 && magic.b16[0] == XZ_MAGIC1 225 && magic.b16[0] == XZ_MAGIC1
230 ) { 226 ) {
231 offset = -6; 227 xstate->signature_skipped = 6;
232 xread(fd, magic.b32, sizeof(magic.b32[0])); 228 xread(fd, magic.b32, sizeof(magic.b32[0]));
233 if (magic.b32[0] == XZ_MAGIC2) { 229 if (magic.b32[0] == XZ_MAGIC2) {
234 xstate->xformer = unpack_xz_stream; 230 xstate->xformer = unpack_xz_stream;
@@ -250,18 +246,8 @@ static transformer_state_t *setup_transformer_on_fd(int fd, int fail_if_not_comp
250 */ 246 */
251// USE_FOR_MMU(xstate->xformer = copy_stream;) 247// USE_FOR_MMU(xstate->xformer = copy_stream;)
252// USE_FOR_NOMMU(xstate->xformer_prog = "cat";) 248// USE_FOR_NOMMU(xstate->xformer_prog = "cat";)
253 /* fall through to seeking bck over bytes we read earlier */
254
255 USE_FOR_NOMMU(found_magic:)
256 /* NOMMU version of fork_transformer execs
257 * an external unzipper that wants
258 * file position at the start of the file.
259 */
260 xlseek(fd, offset, SEEK_CUR);
261
262 USE_FOR_MMU(found_magic:)
263 /* In MMU case, if magic was found, seeking back is not necessary */
264 249
250 found_magic:
265 return xstate; 251 return xstate;
266} 252}
267 253
@@ -280,6 +266,12 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_compressed)
280# if BB_MMU 266# if BB_MMU
281 fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer); 267 fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer);
282# else 268# else
269 /* NOMMU version of fork_transformer execs
270 * an external unzipper that wants
271 * file position at the start of the file.
272 */
273 xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
274 xstate->signature_skipped = 0;
283 fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog); 275 fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog);
284# endif 276# endif
285 free(xstate); 277 free(xstate);
@@ -322,14 +314,22 @@ int FAST_FUNC open_zipped(const char *fname, int fail_if_not_compressed)
322 return -1; 314 return -1;
323 315
324 fd = xstate->src_fd; 316 fd = xstate->src_fd;
325 if (xstate->xformer) {
326# if BB_MMU 317# if BB_MMU
327 fork_transformer_with_no_sig(xstate->src_fd, xstate->xformer); 318 if (xstate->xformer) {
319 fork_transformer_with_no_sig(fd, xstate->xformer);
320 } else {
321 /* the file is not compressed */
322 xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
323 xstate->signature_skipped = 0;
324 }
328# else 325# else
329 fork_transformer_with_sig(xstate->src_fd, xstate->xformer, xstate->xformer_prog); 326 /* NOMMU can't avoid the seek :( */
327 xlseek(fd, - xstate->signature_skipped, SEEK_CUR);
328 xstate->signature_skipped = 0;
329 if (xstate->xformer) {
330 fork_transformer_with_sig(fd, xstate->xformer, xstate->xformer_prog);
331 } /* else: the file is not compressed */
330# endif 332# endif
331 }
332 /* else: the file is not compressed */
333 333
334 free(xstate); 334 free(xstate);
335 return fd; 335 return fd;
@@ -357,6 +357,9 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
357 } 357 }
358 } else { 358 } else {
359 /* File is not compressed */ 359 /* File is not compressed */
360//FIXME: avoid seek
361 xlseek(xstate->src_fd, - xstate->signature_skipped, SEEK_CUR);
362 xstate->signature_skipped = 0;
360 image = xmalloc_read(xstate->src_fd, maxsz_p); 363 image = xmalloc_read(xstate->src_fd, maxsz_p);
361 } 364 }
362 365