Samanta Navarro [Tue, 1 Jun 2021 11:25:03 +0000 (11:25 +0000)]
Handle all negative int64_t values in mtree/tar
The variable last_digit_limit is negative since INT64_MIN itself is
negative as well. This means that the last digit after "limit" always
leads to maxval.
Turning last_digit_limit positive in itself is not sufficient because
it would lead to a signed integer overflow during shift operation.
If limit is reached and the last digit is last_digit_limit, the number
is at least maxval. The already existing if condition for even larger
(or smaller) values can be reused to prevent the last shift.
In my humble opinion it might make sense to reduce duplicated code and
keep it separated in a utility source file for shared use.
Owen W. Taylor [Wed, 12 May 2021 20:26:24 +0000 (16:26 -0400)]
On close, handle short writes from archive_write_callback
The archive_write_callback passed to archive_write_open() is documented as:
"each call to the write callback function should translate to a single write(2) system call.
On success, the write callback should return the number of bytes actually written"
And in most places, the code repeatedly calls the write callback, but when flushing
the buffer at close, the write callback was called once, assuming it would write everything.
This could result in a truncated archive.
A test is added to test short writes in different code paths.
Owen W. Taylor [Wed, 12 May 2021 20:37:16 +0000 (16:37 -0400)]
Avoid getcwd(0, PATH_MAX) for GNU libc
Recent versions of GNU libc and GCC produce a warning on getcwd(0, PATH_MAX):
test_main.c: In function ‘get_refdir’:
test_main.c:3684:8: error: argument 1 is null but the corresponding size argument 2 value is 4096 [-Werror=nonnull]
3684 | pwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
This is because getcwd() is marked with the 'write_only (1, 2)' attribute.
Using the alternate getcwd(NULL, 0) path which is supported by GNU libc avoids this.
Wei-Cheng Pan [Tue, 9 Mar 2021 16:34:55 +0000 (16:34 +0000)]
fix rar header skiming
The available size returned from `__archive_read_ahead` can be larger
then required size. Substract by available size may underflow `skip`,
which will reach EOF too soon.
Christos Zoulas [Mon, 29 Mar 2021 19:32:34 +0000 (15:32 -0400)]
Extract common transfer setting code for statfs and statvfs.
1. Makes detection of f_iosize constent.
2. Avoid infinite loops by detecting 0 sizes and converting to -1.
This happens with FUSE. NetBSD PR/56083.
Tim Kientzle [Sat, 27 Mar 2021 04:50:41 +0000 (21:50 -0700)]
Merge pull request #1514 from pimaster/fixDiskAccessForPrePaddedZips
Rather than using the central directory offset as the file position directly, instead use the known location of the end-of-central-directory record and the size of the central directory to compute an offset. This allows us to efficiently handle Zip archives that have other data prepended to the file.
Russell Mullens [Tue, 23 Mar 2021 11:22:07 +0000 (22:22 +1100)]
Fix excessive disk read for padded zip.
Use the size of the Central Directory and the offset of the EOCD to
calculate the real position.
This trick doesn't work for Zip64 as easily as we are not scanning
backwards to find the PK\x06\x06 entry.
Interestingly, it is never checked so it could be trying to parse
bad files.
Russell Mullens [Sat, 20 Mar 2021 07:59:12 +0000 (18:59 +1100)]
Calculate where the Central Directory is based on the size of the Central Directory in EOCD and where the OECD was found.
This prevents large reads when a zip archive is preceded by other data.
Alex Richardson [Wed, 10 Mar 2021 10:31:28 +0000 (10:31 +0000)]
Silence stderr in test_read_append_filter_program
When the FreeBSD testsuite runs the libarchive tests it checks that stderr
is empty. Since #1382 this is no longer the case. This change restores
the behaviour of silencing bunzip2 stderr but doesn't bring back the
output text check.
Oleg Smirnov [Fri, 22 Jan 2021 11:16:14 +0000 (14:16 +0300)]
Fix #1486: build fails on Windows with VS2013 toolset (v120)
Build fails on compiling xxhash.c having a fuction with "inline" specifier.
"inline" is a c99 keyword and c99 is not yet (fully) supported with MSVC toolset v120:
"The inline keyword is available only in C++. The __inline and __forceinline
keywords are available in both C and C++. For compatibility with previous versions,
_inline is a synonym for __inline."
(Source: http://msdn.microsoft.com/en-us/library/z8y1yy88.aspx)
This fix adds a patch that replaces "inline" with "__inline" in xxhash.c
Otherwise, the preprocessor is not detected and it leads to failure with
empty $CPP variable being used on la_TYPE_UID_T, leading to a cascade of
detection errors and redefinition of some types.
Alex Richardson [Wed, 9 Dec 2020 16:17:22 +0000 (16:17 +0000)]
warc: Fix undefined behaviour in deconst() function
Creating a pointer by adding an offset to 0x1 is undefined behaviour and
results in an invalid pointer when running on CHERI systems. Use a
standards-compliant cast via uintptr_t instead.
This was found due to a crash while running the libarchive test suite on a
CHERI-RISC-V system.
Martin Matuska [Fri, 6 Nov 2020 02:17:11 +0000 (03:17 +0100)]
Introduce archive_write_open2() with free callback
The archive_write_open() function does not provide a free callback.
Freeing was done by the close callback. When the open callback fails,
the client filter is left in ARCHIVE_WRITE_FILTER_STATE_FATAL,
the close callback is not called and unfreed resources may be left behind.
HBSD: Teach libarchive about the system extended attribute namespace
In order to teach the packaging infrastructure how to support
HardenedBSD's method of exploit mitigation toggling, teach libarchive
how to handle the system filesystem extended attribute namespace.
Shawn Webb [Sun, 9 Aug 2020 12:15:06 +0000 (08:15 -0400)]
HBSD: wrap function declaration in an ifdef to appease CI
The function I added only applies to FreeBSD. As such, if the function
declaration isn't ifdef'd out for other architectures, continuous
integration (CI) builds fail. Mitigate the failure by guarding the
function declaration with the proper preprocessor macro conditional.
HBSD: Teach libarchive about the system extended attribute namespace
In order to teach HardenedBSD's packaging infrastructure how to support
HardenedBSD's method of exploit mitigation toggling, teach libarchive
how to handle the system filesystem extended attribute namespace.
Luis Henriques [Fri, 25 Sep 2020 09:09:44 +0000 (10:09 +0100)]
Fix test clean-up
On test clean-up an 'rm -rf' will fail because 'lock' and 'lock/lock2'
directories have 0311 permissions. Change these permissions on exit so
that the directories can be deleted on success.
Alex Richardson [Thu, 17 Sep 2020 17:14:58 +0000 (18:14 +0100)]
Avoid mismatch between library and test crypto configuration
I was investigating libarchive test failures on FreeBSD and it turns out
we get a reproducible SIGBUS for test_archive_m5, etc. Debugging this shows
that libarchive and the tests disagree when it comes to the definition of
archive_md5_ctx: libarchive assumes it's the OpenSSL type whereas the test
use the libmd type. The latter is not necessarily aligned enough to store
a pointer (16 bytes for CHERI RISC-V), so we were crashing when storing
EVP_MD_CTX* to an 8-byte-aligned archive_md5_ctx.
To avoid problems like this in the future, add a new macro to the config
header and use that to ensure that all configuration check macros have
been defined in archive_digest_private.h.