Steve Lhomme [Wed, 24 May 2023 13:23:14 +0000 (15:23 +0200)]
Don't call GetOEMCP() in Universal Windows Platform builds
It's not available [1] [2]. However we can use the intermediate CP_OEMCP
value. It can be used to compare charsets in create_sconv_object().
It won't work with comparing charsets in archive_string_default_conversion_for_read()
and archive_string_default_conversion_for_write(). current_codepage being
an actual CodePage value.
Usually it's built-in but make sure we have it on by default.
We don't need to rename the windows static library when it's the only one built.
This will also allow proper usage of the pkg-config file in this case. Otherwise
there is no way to select the static library that way.
Note that test_read_format_7zip_lzma2_arm passes, while
test_read_format_7zip_zstd_arm fails, I believe because
liblzma implements these filters internally for itself, unlike the
other compression libraries.
These two archives contain a linux C hello world executable, built for
gnueabihf. They were created like so (the first one using a fork of
7-zip with zstandard support):
7z a -t7z -m0=zstd -mf=ARM libarchive/test/test_read_format_7zip_zstd_arm.7z hw-gnueabihf
and
7z a -t7z -m0=lzma2 -mf=ARM libarchive/test/test_read_format_7zip_lzma2_arm.7z hw-gnueabihf
7zip reader: add support for zstandard compression in 7z archives
Zstandard support is not yet available in 7-Zip, though it is planned
for a future release:
https://sourceforge.net/p/sevenzip/feature-requests/1580/
The compression ID used here (4F71101) is copied from a popular 7-Zip
fork, which added ZSTD support back in 2017, and is mentioned in the
upstream 7-Zip ticket linked above:
https://github.com/mcmilk/7-Zip-zstd.git
Note that this does not add write support for Zstandard compression
in 7z archives.
There is a popular 7-Zip fork with zstandard support, with releases as
far back as 2017:
https://github.com/mcmilk/7-Zip-zstd.git
Zstandard support is not yet available in 7-Zip, though it is planned
for a future release:
https://sourceforge.net/p/sevenzip/feature-requests/1580/
This change adds a couple of tests for reading 7-Zip archives which
use zstandard compression. They are expected to fail until support is
added in the following commit.
Luke Mewburn [Sat, 10 Jun 2023 10:44:52 +0000 (11:44 +0100)]
setup_current_filesystem: fail if name_max is 0
Add error handling to the USE_READDIR_R code paths that set name_max
from struct statfs or statvfs; if the determined name_max == 0
then return an error.
Avoids a crash in tree_dir_next_posix() when the calculation of
dirent_size from name_max is too small for the memory allocated
for struct dirent.
This may fix Github issue #1149
This may fix NetBSD PR https://gnats.netbsd.org/56080
Enji Cooper [Sat, 13 May 2023 04:11:07 +0000 (21:11 -0700)]
Fix FreeBSD builds with WARNS=6 (#1869)
WARNS=6 on FreeBSD passes several CFLAGS that causes the previous code
to fail with `-Wincompatible-pointer-types-discards-qualifiers` when
compiled with clang.
This particular change adjusts the code to be
`-Wincompatible-pointer-types-discards-qualifiers` clean. This change
changes the calls to use OSSL_PARAM macro abbreviated calls, instead of
calling more verbose (and less documented) callers.
While here, also address a `mac` object leak if `ctx` cannot be
allocated cleanly by always free'ing `mac` after it's been attached to
`ctx`.
Co-authored-by: Pierre Pronchery <pierre@freebsdfoundation.org>
Sponsored by: The FreeBSD Foundation
Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
Make single bit bitfields unsigned to avoid clang 16 warning (#1860)
Clang 16 introduced a warning about single bit bitfields in structs,
which is triggered by a few libarchive formats:
libarchive/archive_write_set_format_7zip.c:1541:13: error: implicit
truncation from 'int' to a one-bit wide bit-field changes value from 1
to -1 [-Werror,-Wsingle-bit-bitfield-constant-conversion]
file->dir = 1;
^ ~
This is because single bit bitfields only support values -1 and 0, if
they are signed.
For bitfields with two or more bits this can be intentional, but single
bit bitfields are typically used as booleans, so it is better to make
them unsigned.
Without this patch, `bsdcpio_test_option_c` failed after 2038-01-19 with
```
.../libarchive-3.6.2/cpio/test/test_option_c.c:143: Assertion failed: t >= now - 2
.../libarchive-3.6.2/cpio/test/test_option_c.c:169: Assertion failed: t >= now - 2
.../libarchive-3.6.2/cpio/test/test_option_c.c:205: Assertion failed: t >= now - 2
```
Background:
As part of my work on reproducible builds for openSUSE, I check that
software still gives identical build results in the future.
The usual offset is +16 years, because that is how long I expect some
software will be used in some places.
This showed up failing tests in our package build.
See https://reproducible-builds.org/ for why this matters.
When the `zstd:frame-per-file` option is specified, the zstd filter will start a new frame when flushed, i.e. for each file in the archive.
The `zstd:min-frame-size=N` option modifies the `zstd:frame-per-file` option in that it will not start a new frame unless the current one exceeds `N` bytes.
When the `zstd:max-frame-size=N` option is specified, the zstd filter will start a new frame any time the compressed size of the previous one exceeds `N` bytes.
These options decrease compression efficiency by a varying amount (depending on the exact composition of its contents) but render the tarball seekable, to a certain extent.
* Add a flush() method to write filters.
* Add an __archive_write_filters_flush() function which iterates over filters in order and invokes the flush method for any filter that has one and that has written data.
* Call __archive_write_filters_flush() before writing a new header.
Rosen Penev [Mon, 9 Jan 2023 14:15:55 +0000 (06:15 -0800)]
replace time64 functions with normal ones (#1830)
Otherwise there are 32/64-bit pointer conversions going on. In Windows
since MSVC2005, time_t has been 64-bit. MinGW needs a hack to get 64-bit
time_t.
Peter Pentchev [Wed, 28 Dec 2022 22:04:40 +0000 (00:04 +0200)]
Only add "iconv" to the .pc file if needed (#1825)
Hi,
Thanks for writing and maintaining libarchive!
What do you think about this trivial change that does not add "iconv" to
the pkg-config file's list of required packages unless it is actually
needed? On at least Debian GNU/Linux systems, the iconv(3) function is
part of the system C library and there is no Debian package that
installs an iconv.pc file, so I had to make this change to the Debian
package of libarchive.
Use FILE_SHARE_WRITE and FILE_SHARE_DELETE when opening files on Windows
Many standard libraries(
[libc++](https://github.com/llvm/llvm-project/blob/main/libcxx/src/filesystem/posix_compat.h#L159),
[go](https://cs.opensource.google/go/go/+/refs/tags/go1.19.3:src/syscall/syscall_windows.go;l=331),
[rust](https://doc.rust-lang.org/src/std/os/windows/fs.rs.html#126-131)
) open files on windows with `FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE`
mode by default. Libarchive uses only `FILE_SHARE_READ`, so when file is
being opened by any program that uses these standard libraries
libarchive fails to open it. Here we change libarchive shared flags, so
it plays well with common practice in other programs.
Joris Clement [Fri, 28 Oct 2022 15:22:47 +0000 (17:22 +0200)]
Fix CMake warning
The warnings occurs at least with CMake version 3.24. It is caused by
CMake trying to find the gcc library due to case sensitivity.
The warning message was:
```
CMake Warning (dev) at /usr/share/cmake-3.24/Modules/FindPackageHandleStandardArgs.cmake:438 (message):
The package name passed to `find_package_handle_standard_args` (LIBGCC)
does not match the name of the calling package (LibGCC). This can lead to
problems in calling code that expects `find_package` result variables
(e.g., `_FOUND`) to follow a certain pattern.
Call Stack (most recent call first):
build/cmake/FindLibGCC.cmake:17 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:1269 (FIND_PACKAGE)
This warning is for project developers. Use -Wno-dev to suppress it.
```
Julien Voisin [Thu, 13 Oct 2022 12:13:19 +0000 (14:13 +0200)]
Extend the usage of the DONT_FAIL_ON_CRC_ERROR macro
DONT_FAIL_ON_CRC_ERROR is already used in the rar5 support code, so let's make
use of it in another places as well. This should tremendously help with
fuzzing.
Eric van Gyzen [Fri, 30 Sep 2022 15:28:09 +0000 (10:28 -0500)]
Support reading mtree files with tabs
Commit 45c5008c4 requires all characters in an mtree file to be
printable, as determined by `isprint()`. This broke support for
reading mtree files with tab characters, which are valid and otherwise
supported by libarchive. Allow them. Add a unit test.
John Reiser [Fri, 26 Aug 2022 16:51:19 +0000 (09:51 -0700)]
archive_entry_pathname() tries UTF-8 if MBS returns EILSEQ
For better pathname portability across OS, in particular Windows to Linux.
Original bug: unrar in https://bugzilla.redhat.com/show_bug.cgi?id=2120926
modified: libarchive/archive_entry.c
libarchive: Do not include sys/mount.h when linux/fs.h is present
These headers are in conflict and only one is needed by
archive_read_disk_posix.c therefore include linux/fs.h if it exists
otherwise include sys/mount.h
It also helps compiling with glibc 2.36
where sys/mount.h conflicts with linux/mount.h see [1]
Ben Wagner [Tue, 19 Jul 2022 17:02:40 +0000 (13:02 -0400)]
Validate entry_bytes_remaining in pax_attribute
The `size` attribute may contain a negative or too large value. Check
the range of the `entry_bytes_remaining` in `pax_attribute` the same way
as `header_common`. The test which is added passes both with and without
this change in a normal debug build. It is necessary to run with
`-fsanitize=undefined` to see that the undefined behavior is avoided.