Sync libarchive with vendor. Relevant vendor changes: Issue #795: XAR - do not try to add xattrs without an allocated name PR #812: non-recursive option for extract and list PR #958: support reading metadata from compressed files PR #999: add --exclude-vcs option to bsdtar Issue #1062: treat empty archives with a GNU volume header as valid PR #1074: Handle ZIP files with trailing 0s in the extra fields (Android APK archives) PR #1109: Ignore padding in Zip extra field data (Android APK archives) PR #1167: fix problems related to unreadable directories Issue #1168: fix handling of strtol() and strtoul() PR #1172: RAR5 - fix invalid window buffer read in E8E9 filter PR #1174: ZIP reader - fix of MSZIP signature parsing PR #1175: gzip filter - fix reading files larger than 4GB from memory PR #1177: gzip filter - fix memory leak with repeated header reads PR #1180: ZIP reader - add support for Info-ZIP Unicode Path Extra Field PR #1181: RAR5 - fix merge_block() recursion (OSS-Fuzz 12999, 13029, 13144, 13478, 13490) PR #1183: fix memory leak when decompressing ZIP files with LZMA PR #1184: fix RAR5 OSS-Fuzz issues 12466, 14490, 14491, 12817 OSS-Fuzz 12466: RAR5 - fix buffer overflow when parsing huffman tables OSS-Fuzz 14490, 14491: RAR5 - fix bad shift-left operations OSS-Fuzz 12817: RAR5 - handle a case with truncated huffman tables PR #1186: RAR5 - fix invalid type used for dictionary size mask (OSS-Fuzz 14537) PR #1187: RAR5 - fix integer overflow (OSS-Fuzz 14555) PR #1190: RAR5 - RAR5 don't try to unpack entries marked as directories (OSS-Fuzz 14574) PR #1196: RAR5 - fix a potential SIGSEGV on 32-bit builds OSS-Fuzz 2582: RAR - fix use after free if there is an invalid entry OSS-Fuzz 14331: RAR5 - fix maximum owner name length OSS-Fuzz 13965: RAR5 - use unsigned int for volume number + range check Additional RAR5 reader changes: - support symlinks, hardlinks, file owner, file group, versioned files - change ARCHIVE_FORMAT_RAR_V5 to 0x100000 - set correct mode for readonly directories - support readonly, hidden and system Windows file attributes MFC after: 2 weeks
161 lines
5.4 KiB
C
161 lines
5.4 KiB
C
/*-
|
|
* Copyright (c) 2003-2008 Tim Kientzle
|
|
* 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"
|
|
#if defined(HAVE_UTIME_H)
|
|
#include <utime.h>
|
|
#elif defined(HAVE_SYS_UTIME_H)
|
|
#include <sys/utime.h>
|
|
#endif
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
static struct {
|
|
const char *name;
|
|
time_t atime_sec;
|
|
} files[] = {
|
|
{ "f0", 0 },
|
|
{ "f1", 0 },
|
|
{ "f2", 0 },
|
|
{ "f3", 0 },
|
|
{ "f4", 0 },
|
|
{ "f5", 0 }
|
|
};
|
|
|
|
/*
|
|
* Create a bunch of test files and record their atimes.
|
|
* For the atime preserve/change tests, the files must have
|
|
* atimes in the past. We can accomplish this by explicitly invoking
|
|
* utime() on platforms that support it or by simply sleeping
|
|
* for a second after creating the files. (Creating all of the files
|
|
* at once means we only need to sleep once.)
|
|
*/
|
|
static void
|
|
test_create(void)
|
|
{
|
|
struct stat st;
|
|
struct utimbuf times;
|
|
static const int numfiles = sizeof(files) / sizeof(files[0]);
|
|
int i;
|
|
|
|
for (i = 0; i < numfiles; ++i) {
|
|
/*
|
|
* Note: Have to write at least one byte to the file.
|
|
* cpio doesn't bother reading the file if it's zero length,
|
|
* so the atime never gets changed in that case, which
|
|
* makes the tests below rather pointless.
|
|
*/
|
|
assertMakeFile(files[i].name, 0644, "a");
|
|
|
|
/* If utime() isn't supported on your platform, just
|
|
* #ifdef this section out. Most of the test below is
|
|
* still valid. */
|
|
memset(×, 0, sizeof(times));
|
|
#if defined(_WIN32) && !defined(CYGWIN)
|
|
times.actime = 86400;
|
|
times.modtime = 86400;
|
|
#else
|
|
times.actime = 1;
|
|
times.modtime = 3;
|
|
#endif
|
|
assertEqualInt(0, utime(files[i].name, ×));
|
|
|
|
/* Record whatever atime the file ended up with. */
|
|
/* If utime() is available, this should be 1, but there's
|
|
* no harm in being careful. */
|
|
assertEqualInt(0, stat(files[i].name, &st));
|
|
files[i].atime_sec = st.st_atime;
|
|
}
|
|
|
|
/* Wait until the atime on the last file is actually in the past. */
|
|
sleepUntilAfter(files[numfiles - 1].atime_sec);
|
|
}
|
|
|
|
DEFINE_TEST(test_option_a)
|
|
{
|
|
struct stat st;
|
|
int r;
|
|
char *p;
|
|
|
|
/* Create all of the test files. */
|
|
test_create();
|
|
|
|
/* Sanity check; verify that atimes really do get modified. */
|
|
p = slurpfile(NULL, "f0");
|
|
assert(p != NULL);
|
|
free(p);
|
|
assertEqualInt(0, stat("f0", &st));
|
|
if (st.st_atime == files[0].atime_sec) {
|
|
skipping("Cannot verify -a option\n"
|
|
" Your system appears to not support atime.");
|
|
}
|
|
else
|
|
{
|
|
/*
|
|
* If this disk is mounted noatime, then we can't
|
|
* verify correct operation without -a.
|
|
*/
|
|
|
|
/* Copy the file without -a; should change the atime. */
|
|
r = systemf("echo %s | %s -pd copy-no-a > copy-no-a.out 2>copy-no-a.err", files[1].name, testprog);
|
|
assertEqualInt(r, 0);
|
|
assertTextFileContents("1 block\n", "copy-no-a.err");
|
|
assertEmptyFile("copy-no-a.out");
|
|
assertEqualInt(0, stat(files[1].name, &st));
|
|
failure("Copying file without -a should have changed atime.");
|
|
assert(st.st_atime != files[1].atime_sec);
|
|
|
|
/* Archive the file without -a; should change the atime. */
|
|
r = systemf("echo %s | %s -o > archive-no-a.out 2>archive-no-a.err", files[2].name, testprog);
|
|
assertEqualInt(r, 0);
|
|
assertTextFileContents("1 block\n", "copy-no-a.err");
|
|
assertEqualInt(0, stat(files[2].name, &st));
|
|
failure("Archiving file without -a should have changed atime.");
|
|
assert(st.st_atime != files[2].atime_sec);
|
|
}
|
|
|
|
/*
|
|
* We can, of course, still verify that the atime is unchanged
|
|
* when using the -a option.
|
|
*/
|
|
|
|
/* Copy the file with -a; should not change the atime. */
|
|
r = systemf("echo %s | %s -pad copy-a > copy-a.out 2>copy-a.err",
|
|
files[3].name, testprog);
|
|
assertEqualInt(r, 0);
|
|
assertTextFileContents("1 block\n", "copy-a.err");
|
|
assertEmptyFile("copy-a.out");
|
|
assertEqualInt(0, stat(files[3].name, &st));
|
|
failure("Copying file with -a should not have changed atime.");
|
|
assertEqualInt(st.st_atime, files[3].atime_sec);
|
|
|
|
/* Archive the file with -a; should not change the atime. */
|
|
r = systemf("echo %s | %s -oa > archive-a.out 2>archive-a.err",
|
|
files[4].name, testprog);
|
|
assertEqualInt(r, 0);
|
|
assertTextFileContents("1 block\n", "copy-a.err");
|
|
assertEqualInt(0, stat(files[4].name, &st));
|
|
failure("Archiving file with -a should not have changed atime.");
|
|
assertEqualInt(st.st_atime, files[4].atime_sec);
|
|
}
|