Package: busybox / 1:1.22.0-19

libarchive-open_zipped-does-not-need-to-check-extensions.diff Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
commit 7c47b560a8fc97956dd8132bd7f1863d83c19866
Author: Denys Vlasenko <vda.linux@googlemail.com>
Date:   Fri Jan 10 14:06:57 2014 +0100

    libarchive: open_zipped() does not need to check extensions for e.g. gzip
    
    We only need to check for signature-less extensions,
    currently only .lzma. The rest can be happily autodetected.
    
    This fixes "zcat FILE_WITHOUT_GZ_EXT" case, among others.
    
    Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>

diff --git a/archival/libarchive/open_transformer.c b/archival/libarchive/open_transformer.c
index 4e98264..1aeba13 100644
--- a/archival/libarchive/open_transformer.c
+++ b/archival/libarchive/open_transformer.c
@@ -182,27 +182,26 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
 
 int FAST_FUNC open_zipped(const char *fname)
 {
-	char *sfx;
 	int fd;
 
 	fd = open(fname, O_RDONLY);
 	if (fd < 0)
 		return fd;
 
-	sfx = strrchr(fname, '.');
-	if (sfx) {
-		sfx++;
-		if (ENABLE_FEATURE_SEAMLESS_LZMA && strcmp(sfx, "lzma") == 0)
-			/* .lzma has no header/signature, just trust it */
+	if (ENABLE_FEATURE_SEAMLESS_LZMA) {
+		/* .lzma has no header/signature, can only detect it by extension */
+		char *sfx = strrchr(fname, '.');
+		if (sfx && strcmp(sfx+1, "lzma") == 0) {
 			open_transformer_with_sig(fd, unpack_lzma_stream, "unlzma");
-		else
-		if ((ENABLE_FEATURE_SEAMLESS_GZ && strcmp(sfx, "gz") == 0)
-		 || (ENABLE_FEATURE_SEAMLESS_BZ2 && strcmp(sfx, "bz2") == 0)
-		 || (ENABLE_FEATURE_SEAMLESS_XZ && strcmp(sfx, "xz") == 0)
-		) {
-			setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1);
+			return fd;
 		}
 	}
+	if ((ENABLE_FEATURE_SEAMLESS_GZ)
+	 || (ENABLE_FEATURE_SEAMLESS_BZ2)
+	 || (ENABLE_FEATURE_SEAMLESS_XZ)
+	) {
+		setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1);
+	}
 
 	return fd;
 }