aboutsummaryrefslogtreecommitdiff
path: root/archival
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
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')
-rw-r--r--archival/bbunzip.c2
-rw-r--r--archival/gzip.c4
-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
-rw-r--r--archival/tar.c21
7 files changed, 63 insertions, 48 deletions
diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index aaaf67e03..3a483219d 100644
--- a/archival/bbunzip.c
+++ b/archival/bbunzip.c
@@ -121,7 +121,7 @@ int FAST_FUNC bbunpack(char **argv,
121 121
122 if (!(option_mask32 & SEAMLESS_MAGIC)) { 122 if (!(option_mask32 & SEAMLESS_MAGIC)) {
123 init_transformer_state(&xstate); 123 init_transformer_state(&xstate);
124 xstate.check_signature = 1; 124 xstate.signature_skipped = 0;
125 /*xstate.src_fd = STDIN_FILENO; - already is */ 125 /*xstate.src_fd = STDIN_FILENO; - already is */
126 xstate.dst_fd = STDOUT_FILENO; 126 xstate.dst_fd = STDOUT_FILENO;
127 status = unpacker(&xstate); 127 status = unpacker(&xstate);
diff --git a/archival/gzip.c b/archival/gzip.c
index f9bb3c742..8f1e4ff29 100644
--- a/archival/gzip.c
+++ b/archival/gzip.c
@@ -77,13 +77,15 @@ aa: 85.1% -- replaced with aa.gz
77//kbuild:lib-$(CONFIG_GZIP) += gzip.o 77//kbuild:lib-$(CONFIG_GZIP) += gzip.o
78 78
79//usage:#define gzip_trivial_usage 79//usage:#define gzip_trivial_usage
80//usage: "[-cfd" IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..." 80//usage: "[-cf" IF_GUNZIP("d") IF_FEATURE_GZIP_LEVELS("123456789") "] [FILE]..."
81//usage:#define gzip_full_usage "\n\n" 81//usage:#define gzip_full_usage "\n\n"
82//usage: "Compress FILEs (or stdin)\n" 82//usage: "Compress FILEs (or stdin)\n"
83//usage: IF_FEATURE_GZIP_LEVELS( 83//usage: IF_FEATURE_GZIP_LEVELS(
84//usage: "\n -1..9 Compression level" 84//usage: "\n -1..9 Compression level"
85//usage: ) 85//usage: )
86//usage: IF_GUNZIP(
86//usage: "\n -d Decompress" 87//usage: "\n -d Decompress"
88//usage: )
87//usage: "\n -c Write to stdout" 89//usage: "\n -c Write to stdout"
88//usage: "\n -f Force" 90//usage: "\n -f Force"
89//usage: 91//usage:
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
diff --git a/archival/tar.c b/archival/tar.c
index c88957734..c87d23597 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -1009,7 +1009,6 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1009 /* Prepend '-' to the first argument if required */ 1009 /* Prepend '-' to the first argument if required */
1010 opt_complementary = "--:" // first arg is options 1010 opt_complementary = "--:" // first arg is options
1011 "tt:vv:" // count -t,-v 1011 "tt:vv:" // count -t,-v
1012 IF_FEATURE_TAR_FROM("X::T::") // cumulative lists
1013#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM 1012#if ENABLE_FEATURE_TAR_LONG_OPTIONS && ENABLE_FEATURE_TAR_FROM
1014 "\xff::" // --exclude=PATTERN is a list 1013 "\xff::" // --exclude=PATTERN is a list
1015#endif 1014#endif
@@ -1061,13 +1060,13 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1061#endif 1060#endif
1062 opt = getopt32(argv, 1061 opt = getopt32(argv,
1063 "txC:f:Oopvk" 1062 "txC:f:Oopvk"
1064 IF_FEATURE_TAR_CREATE( "ch" ) 1063 IF_FEATURE_TAR_CREATE( "ch" )
1065 IF_FEATURE_SEAMLESS_BZ2( "j" ) 1064 IF_FEATURE_SEAMLESS_BZ2( "j" )
1066 IF_FEATURE_SEAMLESS_LZMA("a" ) 1065 IF_FEATURE_SEAMLESS_LZMA("a" )
1067 IF_FEATURE_TAR_FROM( "T:X:") 1066 IF_FEATURE_TAR_FROM( "T:*X:*")
1068 IF_FEATURE_SEAMLESS_GZ( "z" ) 1067 IF_FEATURE_SEAMLESS_GZ( "z" )
1069 IF_FEATURE_SEAMLESS_XZ( "J" ) 1068 IF_FEATURE_SEAMLESS_XZ( "J" )
1070 IF_FEATURE_SEAMLESS_Z( "Z" ) 1069 IF_FEATURE_SEAMLESS_Z( "Z" )
1071 IF_FEATURE_TAR_NOPRESERVE_TIME("m") 1070 IF_FEATURE_TAR_NOPRESERVE_TIME("m")
1072 IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components 1071 IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components
1073 , &base_dir // -C dir 1072 , &base_dir // -C dir
@@ -1228,9 +1227,10 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1228 // /* We need to know whether child (gzip/bzip/etc) exits abnormally */ 1227 // /* We need to know whether child (gzip/bzip/etc) exits abnormally */
1229 // signal(SIGCHLD, check_errors_in_children); 1228 // signal(SIGCHLD, check_errors_in_children);
1230 1229
1230#if ENABLE_FEATURE_TAR_CREATE
1231 /* Create an archive */ 1231 /* Create an archive */
1232 if (opt & OPT_CREATE) { 1232 if (opt & OPT_CREATE) {
1233#if SEAMLESS_COMPRESSION 1233# if SEAMLESS_COMPRESSION
1234 const char *zipMode = NULL; 1234 const char *zipMode = NULL;
1235 if (opt & OPT_COMPRESS) 1235 if (opt & OPT_COMPRESS)
1236 zipMode = "compress"; 1236 zipMode = "compress";
@@ -1242,7 +1242,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1242 zipMode = "lzma"; 1242 zipMode = "lzma";
1243 if (opt & OPT_XZ) 1243 if (opt & OPT_XZ)
1244 zipMode = "xz"; 1244 zipMode = "xz";
1245#endif 1245# endif
1246 /* NB: writeTarFile() closes tar_handle->src_fd */ 1246 /* NB: writeTarFile() closes tar_handle->src_fd */
1247 return writeTarFile(tar_handle->src_fd, verboseFlag, 1247 return writeTarFile(tar_handle->src_fd, verboseFlag,
1248 (opt & OPT_DEREFERENCE ? ACTION_FOLLOWLINKS : 0) 1248 (opt & OPT_DEREFERENCE ? ACTION_FOLLOWLINKS : 0)
@@ -1250,6 +1250,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1250 tar_handle->accept, 1250 tar_handle->accept,
1251 tar_handle->reject, zipMode); 1251 tar_handle->reject, zipMode);
1252 } 1252 }
1253#endif
1253 1254
1254 if (opt & OPT_ANY_COMPRESS) { 1255 if (opt & OPT_ANY_COMPRESS) {
1255 USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_state_t *xstate);) 1256 USE_FOR_MMU(IF_DESKTOP(long long) int FAST_FUNC (*xformer)(transformer_state_t *xstate);)