From: Tim Kientzle Date: Sat, 10 Jan 2015 18:27:11 +0000 (-0800) Subject: Issue 327: tar should accept zero-sized exclude files with -X X-Git-Tag: v3.1.900a~159 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f93e32f4a2e4b67b05d9042346439c169c03a39d;p=thirdparty%2Flibarchive.git Issue 327: tar should accept zero-sized exclude files with -X Key problem: We were using archive_read_format_raw() to read the exclude file which does not accept empty files. Enabling archive_read_format_empty() and reworking the end-of-input handling fixed this. Also add a test for this case to prevent it from regressing. --- diff --git a/libarchive/archive_match.c b/libarchive/archive_match.c index 6fb86445c..74aaacb5a 100644 --- a/libarchive/archive_match.c +++ b/libarchive/archive_match.c @@ -580,6 +580,7 @@ add_pattern_from_file(struct archive_match *a, struct match_list *mlist, return (ARCHIVE_FATAL); } r = archive_read_support_format_raw(ar); + r = archive_read_support_format_empty(ar); if (r != ARCHIVE_OK) { archive_copy_error(&(a->archive), ar); archive_read_free(ar); @@ -596,9 +597,13 @@ add_pattern_from_file(struct archive_match *a, struct match_list *mlist, } r = archive_read_next_header(ar, &ae); if (r != ARCHIVE_OK) { - archive_copy_error(&(a->archive), ar); archive_read_free(ar); - return (r); + if (r == ARCHIVE_EOF) { + return (ARCHIVE_OK); + } else { + archive_copy_error(&(a->archive), ar); + return (r); + } } archive_string_init(&as); diff --git a/tar/test/test_option_X_upper.c b/tar/test/test_option_X_upper.c index 1aa21fc90..4916af297 100644 --- a/tar/test/test_option_X_upper.c +++ b/tar/test/test_option_X_upper.c @@ -142,4 +142,18 @@ DEFINE_TEST(test_option_X_upper) assertEmptyFile("test.out"); assertEmptyFile("test.err"); assertChdir(".."); + + /* Test 8: with empty exclusions file */ + assertMakeDir("test8", 0755); + assertChdir("test8"); + assertMakeFile("exclusions", 0644, ""); + assertEqualInt(0, + systemf("%s -xf ../archive.tar -X exclusions >test.out 2>test.err", testprog)); + assertFileContents("file1", 5, "file1"); + assertFileContents("file2", 5, "file2"); + assertFileContents("file3a", 6, "file3a"); + assertFileContents("file4a", 6, "file4a"); + assertEmptyFile("test.out"); + assertEmptyFile("test.err"); + assertChdir(".."); }