1 /*- 2 * Copyright (c) 2003-2007 Tim Kientzle 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 #include "test.h" 26 27 /* 28 * Background: There are two written standards for the tar file format. 29 * The first is the POSIX 1988 "ustar" format, the second is the 2001 30 * "pax extended" format that builds on the "ustar" format by adding 31 * support for generic additional attributes. Buried in the details 32 * is one frustrating incompatibility: The 1988 standard says that 33 * tar readers MUST ignore the size field on hardlink entries; the 34 * 2001 standard says that tar readers MUST obey the size field on 35 * hardlink entries. libarchive tries to navigate this particular 36 * minefield by using auto-detect logic to guess whether it should 37 * or should not obey the size field. 38 * 39 * This test tries to probe the boundaries of such handling; the test 40 * archives here were adapted from real archives created by real 41 * tar implementations that are (as of early 2008) apparently still 42 * in use. 43 */ 44 45 static void 46 test_compat_tar_hardlink_1(void) 47 { 48 char name[] = "test_compat_tar_hardlink_1.tar"; 49 struct archive_entry *ae; 50 struct archive *a; 51 52 assert((a = archive_read_new()) != NULL); 53 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 54 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 55 extract_reference_file(name); 56 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240)); 57 58 /* Read first entry, which is a regular file. */ 59 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 60 assertEqualString("xmcd-3.3.2/docs_d/READMf", 61 archive_entry_pathname(ae)); 62 assertEqualString(NULL, archive_entry_hardlink(ae)); 63 assertEqualInt(321, archive_entry_size(ae)); 64 assertEqualInt(1082575645, archive_entry_mtime(ae)); 65 assertEqualInt(1851, archive_entry_uid(ae)); 66 assertEqualInt(3, archive_entry_gid(ae)); 67 assertEqualInt(0100444, archive_entry_mode(ae)); 68 69 /* Read second entry, which is a hard link at the end of archive. */ 70 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 71 assertEqualString("xmcd-3.3.2/README", 72 archive_entry_pathname(ae)); 73 assertEqualString( 74 "xmcd-3.3.2/docs_d/READMf", 75 archive_entry_hardlink(ae)); 76 assertEqualInt(0, archive_entry_size(ae)); 77 assertEqualInt(1082575645, archive_entry_mtime(ae)); 78 assertEqualInt(1851, archive_entry_uid(ae)); 79 assertEqualInt(3, archive_entry_gid(ae)); 80 assertEqualInt(0100444, archive_entry_mode(ae)); 81 82 /* Verify the end-of-archive. */ 83 /* 84 * This failed in libarchive 2.4.12 because the tar reader 85 * tried to obey the size field for the hard link and ended 86 * up running past the end of the file. 87 */ 88 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 89 90 /* Verify that the format detection worked. */ 91 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_NONE); 92 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR); 93 94 assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 95 assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 96 } 97 98 DEFINE_TEST(test_compat_tar_hardlink) 99 { 100 test_compat_tar_hardlink_1(); 101 } 102 103 104