aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-02-06 20:01:11 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2011-02-06 20:01:11 +0100
commitaef441cb4d567da5575c498141b21eb38dc3fdaf (patch)
treef99a2ebecd77c614f243c4df859ee40f7281f9bc
parentca18e25525267736e7e919987c50569f27d70d36 (diff)
downloadbusybox-w32-aef441cb4d567da5575c498141b21eb38dc3fdaf.tar.gz
busybox-w32-aef441cb4d567da5575c498141b21eb38dc3fdaf.tar.bz2
busybox-w32-aef441cb4d567da5575c498141b21eb38dc3fdaf.zip
tar: fix a bug where autodetection messes up -z on extract
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--archival/libarchive/get_header_tar_gz.c4
-rw-r--r--archival/tar.c6
-rw-r--r--include/archive.h20
-rwxr-xr-xtestsuite/tar.tests14
4 files changed, 30 insertions, 14 deletions
diff --git a/archival/libarchive/get_header_tar_gz.c b/archival/libarchive/get_header_tar_gz.c
index b09f8691c..889fed0d9 100644
--- a/archival/libarchive/get_header_tar_gz.c
+++ b/archival/libarchive/get_header_tar_gz.c
@@ -9,7 +9,7 @@
9char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle) 9char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle)
10{ 10{
11#if BB_MMU 11#if BB_MMU
12 unsigned char magic[2]; 12 uint16_t magic;
13#endif 13#endif
14 14
15 /* Can't lseek over pipes */ 15 /* Can't lseek over pipes */
@@ -21,7 +21,7 @@ char FAST_FUNC get_header_tar_gz(archive_handle_t *archive_handle)
21#if BB_MMU 21#if BB_MMU
22 xread(archive_handle->src_fd, &magic, 2); 22 xread(archive_handle->src_fd, &magic, 2);
23 /* Can skip this check, but error message will be less clear */ 23 /* Can skip this check, but error message will be less clear */
24 if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { 24 if (magic != GZIP_MAGIC) {
25 bb_error_msg_and_die("invalid gzip magic"); 25 bb_error_msg_and_die("invalid gzip magic");
26 } 26 }
27#endif 27#endif
diff --git a/archival/tar.c b/archival/tar.c
index e9dc41fe1..1e3cecf44 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -1060,8 +1060,10 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
1060 tar_handle->src_fd = tar_fd; 1060 tar_handle->src_fd = tar_fd;
1061 tar_handle->seek = seek_by_read; 1061 tar_handle->seek = seek_by_read;
1062 } else { 1062 } else {
1063 if (ENABLE_FEATURE_TAR_AUTODETECT && flags == O_RDONLY) { 1063 if (ENABLE_FEATURE_TAR_AUTODETECT
1064 get_header_ptr = get_header_tar; 1064 && flags == O_RDONLY
1065 && get_header_ptr == get_header_tar
1066 ) {
1065 tar_handle->src_fd = open_zipped(tar_filename); 1067 tar_handle->src_fd = open_zipped(tar_filename);
1066 if (tar_handle->src_fd < 0) 1068 if (tar_handle->src_fd < 0)
1067 bb_perror_msg_and_die("can't open '%s'", tar_filename); 1069 bb_perror_msg_and_die("can't open '%s'", tar_filename);
diff --git a/include/archive.h b/include/archive.h
index ba6d323e0..49c478728 100644
--- a/include/archive.h
+++ b/include/archive.h
@@ -8,22 +8,22 @@ enum {
8#if BB_BIG_ENDIAN 8#if BB_BIG_ENDIAN
9 COMPRESS_MAGIC = 0x1f9d, 9 COMPRESS_MAGIC = 0x1f9d,
10 GZIP_MAGIC = 0x1f8b, 10 GZIP_MAGIC = 0x1f8b,
11 BZIP2_MAGIC = 'B' * 256 + 'Z', 11 BZIP2_MAGIC = 256 * 'B' + 'Z',
12 /* .xz signature: 0xfd, '7', 'z', 'X', 'Z', 0x00 */ 12 /* .xz signature: 0xfd, '7', 'z', 'X', 'Z', 0x00 */
13 /* More info at: http://tukaani.org/xz/xz-file-format.txt */ 13 /* More info at: http://tukaani.org/xz/xz-file-format.txt */
14 XZ_MAGIC1 = 0xfd * 256 + '7', 14 XZ_MAGIC1 = 256 * 0xfd + '7',
15 XZ_MAGIC2 = (('z' * 256 + 'X') * 256 + 'Z') * 256 + 0, 15 XZ_MAGIC2 = 256 * (256 * (256 * 'z' + 'X') + 'Z') + 0,
16 /* Different form: 32 bits, then 16 bits: */ 16 /* Different form: 32 bits, then 16 bits: */
17 XZ_MAGIC1a = ((0xfd * 256 + '7') * 256 + 'z') * 256 + 'X', 17 XZ_MAGIC1a = 256 * (256 * (256 * 0xfd + '7') + 'z') + 'X',
18 XZ_MAGIC2a = 'Z' * 256 + 0, 18 XZ_MAGIC2a = 256 * 'Z' + 0,
19#else 19#else
20 COMPRESS_MAGIC = 0x9d1f, 20 COMPRESS_MAGIC = 0x9d1f,
21 GZIP_MAGIC = 0x8b1f, 21 GZIP_MAGIC = 0x8b1f,
22 BZIP2_MAGIC = 'Z' * 256 + 'B', 22 BZIP2_MAGIC = 'B' + 'Z' * 256,
23 XZ_MAGIC1 = '7' * 256 + 0xfd, 23 XZ_MAGIC1 = 0xfd + '7' * 256,
24 XZ_MAGIC2 = ((0 * 256 + 'Z') * 256 + 'X') * 256 + 'z', 24 XZ_MAGIC2 = 'z' + ('X' + ('Z' + 0 * 256) * 256) * 256,
25 XZ_MAGIC1a = (('X' * 256 + 'z') * 256 + '7') * 256 + 0xfd, 25 XZ_MAGIC1a = 0xfd + ('7' + ('z' + 'X' * 256) * 256) * 256,
26 XZ_MAGIC2a = 0 * 256 + 'Z', 26 XZ_MAGIC2a = 'Z' + 0 * 256,
27#endif 27#endif
28}; 28};
29 29
diff --git a/testsuite/tar.tests b/testsuite/tar.tests
index f2f4e9348..824d6d54e 100755
--- a/testsuite/tar.tests
+++ b/testsuite/tar.tests
@@ -154,6 +154,20 @@ dr-xr-x--- input_dir
154SKIP= 154SKIP=
155} 155}
156 156
157# Had a bug where on extrace autodetect first "switched off" -z
158# and then failed to recognize .tgz extension
159testing "tar extract tgz" "\
160dd count=1 bs=1M if=/dev/zero of=F0 2>/dev/null
161tar -czf F0.tgz F0
162rm F0
163tar -xzvf F0.tgz && echo Ok
164rm F0 || echo BAD
165" "\
166F0
167Ok
168" \
169"" ""
170
157 171
158cd .. && rm -rf tar.tempdir || exit 1 172cd .. && rm -rf tar.tempdir || exit 1
159 173