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 __FBSDID("$FreeBSD$"); 27 28 /* 29 * Background: There are two written standards for the tar file format. 30 * The first is the POSIX 1988 "ustar" format, the second is the 2001 31 * "pax extended" format that builds on the "ustar" format by adding 32 * support for generic additional attributes. Buried in the details 33 * is one frustrating incompatibility: The 1988 standard says that 34 * tar readers MUST ignore the size field on hardlink entries; the 35 * 2001 standard says that tar readers MUST obey the size field on 36 * hardlink entries. libarchive tries to navigate this particular 37 * minefield by using auto-detect logic to guess whether it should 38 * or should not obey the size field. 39 * 40 * This test tries to probe the boundaries of such handling; the test 41 * archives here were adapted from real archives created by real 42 * tar implementations that are (as of early 2008) apparently still 43 * in use. 44 */ 45 46 static void 47 test_compat_tar_hardlink_1(void) 48 { 49 char name[] = "test_compat_tar_hardlink_1.tar"; 50 struct archive_entry *ae; 51 struct archive *a; 52 53 assert((a = archive_read_new()) != NULL); 54 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a)); 55 assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a)); 56 extract_reference_file(name); 57 assertEqualIntA(a, ARCHIVE_OK, archive_read_open_filename(a, name, 10240)); 58 59 /* Read first entry, which is a regular file. */ 60 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 61 assertEqualString("xmcd-3.3.2/docs_d/READMf", 62 archive_entry_pathname(ae)); 63 assertEqualString(NULL, archive_entry_hardlink(ae)); 64 assertEqualInt(321, archive_entry_size(ae)); 65 assertEqualInt(1082575645, archive_entry_mtime(ae)); 66 assertEqualInt(1851, archive_entry_uid(ae)); 67 assertEqualInt(3, archive_entry_gid(ae)); 68 assertEqualInt(0100444, archive_entry_mode(ae)); 69 70 /* Read second entry, which is a hard link at the end of archive. */ 71 assertEqualIntA(a, ARCHIVE_OK, archive_read_next_header(a, &ae)); 72 assertEqualString("xmcd-3.3.2/README", 73 archive_entry_pathname(ae)); 74 assertEqualString( 75 "xmcd-3.3.2/docs_d/READMf", 76 archive_entry_hardlink(ae)); 77 assertEqualInt(0, archive_entry_size(ae)); 78 assertEqualInt(1082575645, archive_entry_mtime(ae)); 79 assertEqualInt(1851, archive_entry_uid(ae)); 80 assertEqualInt(3, archive_entry_gid(ae)); 81 assertEqualInt(0100444, archive_entry_mode(ae)); 82 83 /* Verify the end-of-archive. */ 84 /* 85 * This failed in libarchive 2.4.12 because the tar reader 86 * tried to obey the size field for the hard link and ended 87 * up running past the end of the file. 88 */ 89 assertEqualIntA(a, ARCHIVE_EOF, archive_read_next_header(a, &ae)); 90 91 /* Verify that the format detection worked. */ 92 assertEqualInt(archive_filter_code(a, 0), ARCHIVE_FILTER_NONE); 93 assertEqualInt(archive_format(a), ARCHIVE_FORMAT_TAR); 94 95 assertEqualInt(ARCHIVE_OK, archive_read_close(a)); 96 assertEqualInt(ARCHIVE_OK, archive_read_free(a)); 97 } 98 99 DEFINE_TEST(test_compat_tar_hardlink) 100 { 101 test_compat_tar_hardlink_1(); 102 } 103 104 105