]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Improve compatibility to uudecode command.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Mon, 8 Oct 2012 02:27:52 +0000 (11:27 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Mon, 8 Oct 2012 02:45:38 +0000 (11:45 +0900)
Ignore junk data after an end sequence detected.

Makefile.am
libarchive/archive_read_support_filter_uu.c
libarchive/test/CMakeLists.txt
libarchive/test/test_compat_uudecode.c [new file with mode: 0644]

index c2fda595457f9d0c1acf2c9493983e60104c14fd..166f4b6da0923cba7ea0b1969e22fb36688dc58d 100644 (file)
@@ -310,6 +310,7 @@ libarchive_test_SOURCES=                                    \
        libarchive/test/test_compat_solaris_tar_acl.c           \
        libarchive/test/test_compat_solaris_pax_sparse.c        \
        libarchive/test/test_compat_tar_hardlink.c              \
+       libarchive/test/test_compat_uudecode.c                  \
        libarchive/test/test_compat_xz.c                        \
        libarchive/test/test_compat_zip.c                       \
        libarchive/test/test_empty_write.c                      \
index 4afb5ae119af689a8377cb1fe709b20c952b4f0e..42223f1b7841bb6475b8eb65788eb0123cbef160 100644 (file)
@@ -56,6 +56,7 @@ struct uudecode {
 #define ST_READ_UU     1
 #define ST_UUEND       2
 #define ST_READ_BASE64 3
+#define ST_IGNORE      4
 };
 
 static int     uudecode_bidder_bid(struct archive_read_filter_bidder *,
@@ -470,6 +471,10 @@ read_more:
        total = 0;
        out = uudecode->out_buff;
        ravail = avail_in;
+       if (uudecode->state == ST_IGNORE) {
+               used = avail_in;
+               goto finish;
+       }
        if (uudecode->in_cnt) {
                /*
                 * If there is remaining data which is saved by
@@ -491,6 +496,12 @@ read_more:
                len = get_line(b, avail_in - used, &nl);
                if (len < 0) {
                        /* Non-ascii character is found. */
+                       if (uudecode->state == ST_FIND_HEAD &&
+                           (uudecode->total > 0 || total > 0)) {
+                               uudecode->state = ST_IGNORE;
+                               used = avail_in;
+                               goto finish;
+                       }
                        archive_set_error(&self->archive->archive,
                            ARCHIVE_ERRNO_MISC,
                            "Insufficient compressed data");
index 7f113558ffde6e09b9dd14cd3ccba21af61dca68..b5a1e6ce4039d4bd800e4380fa98a59d3158d902 100644 (file)
@@ -53,6 +53,7 @@ IF(ENABLE_TEST)
     test_compat_solaris_tar_acl.c
     test_compat_solaris_pax_sparse.c
     test_compat_tar_hardlink.c
+    test_compat_uudecode.c
     test_compat_xz.c
     test_compat_zip.c
     test_empty_write.c
diff --git a/libarchive/test/test_compat_uudecode.c b/libarchive/test/test_compat_uudecode.c
new file mode 100644 (file)
index 0000000..95b1c9a
--- /dev/null
@@ -0,0 +1,63 @@
+/*-
+ * Copyright (c) 2003-2007 Tim Kientzle
+ * Copyright (c) 2012 Michihiro NAKAJIMA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include "test.h"
+__FBSDID("$FreeBSD$");
+
+static char archive_data[] = {
+"begin 644 test_read_uu.Z\n"
+"M'YV0+@`('$BPH,&#\"!,J7,BP(4(8$&_4J`$\"`,08$F%4O)AQ(\\2/(#7&@#%C\n"
+"M!@T8-##.L`$\"QL@:-F(``%'#H<V;.'/J!%!G#ITP<BS\"H).FS<Z$1(T>/1A2\n"
+"IHU\"0%9=*G4JUJM6K6+-JW<JUJ]>O8,.*'4NVK-FS:-.J7<NVK=NW9P$`\n"
+"`\n"
+"end\n"
+"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
+};
+
+/*
+ * Compatibility: uudecode command ignores junk data placed ater the "end"
+ * marker.
+ */
+DEFINE_TEST(test_compat_uudecode)
+{
+       struct archive_entry *ae;
+       struct archive *a;
+
+       assert((a = archive_read_new()) != NULL);
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
+       assertEqualIntA(a, ARCHIVE_OK,
+           read_open_memory(a, archive_data, sizeof(archive_data), 2));
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae));
+       assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_COMPRESS);
+       assertEqualInt(archive_filter_code(a, 1), ARCHIVE_FILTER_UU);
+       assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR_USTAR);
+       assertEqualIntA(a, ARCHIVE_OK, archive_read_close(a));
+       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
+}
+