Martin Matuska [Wed, 17 Nov 2021 20:06:00 +0000 (21:06 +0100)]
archive_write_disk_posix: fix writing fflags broken in 8a1bd5c
The fixup list was erroneously assumed to be directories only.
Only in the case of critical file flags modification (e.g. SF_IMMUTABLE
on BSD systems), other file types (e.g. regular files or symbolic links)
may be added to the fixup list. We still need to verify that we are writing
to the correct file type, so compare the archive entry file type with
the file type of the file to be modified.
Martin Matuska [Fri, 27 Aug 2021 08:56:28 +0000 (10:56 +0200)]
Fix following symlinks when processing the fixup list
The previous fix in b41daecb5 was incomplete. Fixup entries are
given the original path without calling cleanup_pathname().
To make sure we don't follow a symlink, we must strip trailing
slashes from the path.
The fixup entries are always directories. Make sure we try to modify
only directories by providing O_DIRECTORY to open() (if supported)
and if it fails to check directory via lstat().
Martin Matuska [Sun, 22 Aug 2021 01:53:28 +0000 (03:53 +0200)]
Never follow symlinks when setting file flags on Linux
When opening a file descriptor to set file flags on linux, ensure
no symbolic links are followed. This fixes the case when an archive
contains a directory entry followed by a symlink entry with the same
path. The fixup code would modify file flags of the symlink target.
Martin Matuska [Sat, 21 Aug 2021 07:07:54 +0000 (09:07 +0200)]
write_disk_posix: rename variable in check_symlinks_fsobj()
Rename the flag "extracting_hardlink" to "checking_linkname" to
be more accurate about its use. If the variable is non-zero it
means that check_symlinks_fsobj() is called on the linkname
when a hardlink is going to be created.
Samanta Navarro [Tue, 1 Jun 2021 11:26:30 +0000 (11:26 +0000)]
Fix mutual check in tar sparse handling
GNU.sparse.numbytes and GNU.sparse.offset both have to be set before
gnu_add_sparse_entry can be called.
The GNU.sparse.numbytes parser checks for tar->sparse_numbytes.
This has to be tar->sparse_offset instead to work just like the
GNU.sparse.offset parser.
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.