From: Michihiro NAKAJIMA Date: Mon, 8 Oct 2012 02:27:52 +0000 (+0900) Subject: Improve compatibility to uudecode command. X-Git-Tag: v3.1.0~40^2~77 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=664ea71debc6d0528f45da11ee0f1c937242aa83;p=thirdparty%2Flibarchive.git Improve compatibility to uudecode command. Ignore junk data after an end sequence detected. --- diff --git a/Makefile.am b/Makefile.am index c2fda5954..166f4b6da 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/libarchive/archive_read_support_filter_uu.c b/libarchive/archive_read_support_filter_uu.c index 4afb5ae11..42223f1b7 100644 --- a/libarchive/archive_read_support_filter_uu.c +++ b/libarchive/archive_read_support_filter_uu.c @@ -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"); diff --git a/libarchive/test/CMakeLists.txt b/libarchive/test/CMakeLists.txt index 7f113558f..b5a1e6ce4 100644 --- a/libarchive/test/CMakeLists.txt +++ b/libarchive/test/CMakeLists.txt @@ -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 index 000000000..95b1c9a8b --- /dev/null +++ b/libarchive/test/test_compat_uudecode.c @@ -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/1A2\n" +"IHU\"0%9=*G4JUJM6K6+-JWO8,.*'4NVK-FS:-.J7