]> git.ipfire.org Git - thirdparty/libarchive.git/log
thirdparty/libarchive.git
8 days agoMerge pull request #2691 from kientzle/kientzle-issue2681 master
Tim Kientzle [Sun, 29 Jun 2025 19:03:51 +0000 (12:03 -0700)] 
Merge pull request #2691 from kientzle/kientzle-issue2681

Add missing test file

8 days agoAdd missing test file 2691/head
Tim Kientzle [Sun, 29 Jun 2025 03:45:14 +0000 (20:45 -0700)] 
Add missing test file

9 days agoMerge pull request #2664 from fedegiova/fix_leak_for_cb_error
Tim Kientzle [Sun, 29 Jun 2025 02:15:32 +0000 (19:15 -0700)] 
Merge pull request #2664 from fedegiova/fix_leak_for_cb_error

Fix a memory leak if write callback error early

9 days agoMerge pull request #2658 from stoeckmann/skip_tests
Tim Kientzle [Sun, 29 Jun 2025 02:14:17 +0000 (19:14 -0700)] 
Merge pull request #2658 from stoeckmann/skip_tests

Skip tests if respective support is missing

9 days agoMerge pull request #2673 from 004helix/master
Tim Kientzle [Sun, 29 Jun 2025 02:10:27 +0000 (19:10 -0700)] 
Merge pull request #2673 from 004helix/master

archive_cryptor_private.h: check message digest functions are enabled for windows

9 days agoMerge pull request #2679 from AZero13/error
Tim Kientzle [Sun, 29 Jun 2025 02:09:12 +0000 (19:09 -0700)] 
Merge pull request #2679 from AZero13/error

Handle possible errors from system calls

9 days agoMerge pull request #2687 from hemant-jadhav-emerson/master
Tim Kientzle [Sun, 29 Jun 2025 02:04:30 +0000 (19:04 -0700)] 
Merge pull request #2687 from hemant-jadhav-emerson/master

Supress restrict keyword for msc_ver older than 1927

9 days agoMerge pull request #2689 from ElvishJerricco/linux-fs-flags
Tim Kientzle [Sat, 28 Jun 2025 21:23:02 +0000 (14:23 -0700)] 
Merge pull request #2689 from ElvishJerricco/linux-fs-flags

clear_nochange_fflags: Use linux FS flags

9 days agoMerge pull request #2684 from DHowett/dev/duhowett/shim_open
Tim Kientzle [Sat, 28 Jun 2025 21:22:26 +0000 (14:22 -0700)] 
Merge pull request #2684 from DHowett/dev/duhowett/shim_open

win32: shim wopen, and make both open/wopen use _s "secure" variant

9 days agoMerge pull request #2688 from stoeckmann/entry_off32
Tim Kientzle [Sat, 28 Jun 2025 21:11:17 +0000 (14:11 -0700)] 
Merge pull request #2688 from stoeckmann/entry_off32

Ignore sizes which do not fit into off_t

10 days agoclear_nochange_fflags: Use linux FS flags 2689/head
Will Fancher [Fri, 27 Jun 2025 23:09:15 +0000 (19:09 -0400)] 
clear_nochange_fflags: Use linux FS flags

10 days agoIgnore sizes which do not fit into off_t 2688/head
Tobias Stoeckmann [Fri, 27 Jun 2025 15:06:00 +0000 (17:06 +0200)] 
Ignore sizes which do not fit into off_t

It is possible to handle entries and files with sizes which do not fit
into off_t of the current system (Windows always has 32 bit off_t and
32 bit systems without large file support also have 32 bit off_t).

Set sizes to 0 in such cases. The fstat system call would return -1 and
set errno to EOVERFLOW, but that's not how archive_entry_set_size acts.
It would simply ignore negative values and set the size to 0.

Actual callers of archive_entry_stat from foreign projects seem to not
even check for NULL return values, so let's try to handle such cases as
nice as possible.

Affects mtree's checkfs option as well (Windows only, 32 bit systems
would simply fail in fstat/stat).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
11 days agowin32: shim wopen, and make both open/wopen use _s "secure" variant 2684/head
Dustin Howett [Fri, 15 Oct 2021 22:47:53 +0000 (17:47 -0500)] 
win32: shim wopen, and make both open/wopen use _s "secure" variant

The new `__la_wopen` wrapper is a copy of `__la_open` that
expects--rather than converts--a wcs parameter.

The `sopen` variants are offered as "more secure" variants of `open` and
`wopen`; I cannot vouch for their security, but some build systems are
strict about the use of "banned insecure APIs".

I've confirmed that `_wsopen_s` and `_open_s` are present in the Windows
Vista SDK.

I did not confirm that they are available in the Windows XP Platform
SDK, in part because in e61afbd463d1 (2016!) Tim says:

> I'd like to completely remove support for WinXP and earlier.

2 weeks agoHandle possible errors from system calls 2679/head
Rose [Fri, 20 Jun 2025 17:21:07 +0000 (13:21 -0400)] 
Handle possible errors from system calls

dup, open, etc, can fail and we should not assume they do not.

2 weeks agoMerge pull request #2672 from AZero13/ferror
Tim Kientzle [Fri, 20 Jun 2025 21:33:45 +0000 (14:33 -0700)] 
Merge pull request #2672 from AZero13/ferror

Fix error checking in writing files

2 weeks agoFix error checking in writing files 2672/head
Rose [Wed, 11 Jun 2025 19:21:46 +0000 (15:21 -0400)] 
Fix error checking in writing files

For write, 0 may not mean an error at all. We need to instead check for the length not being the same.

With fwrite, because 0 could mean an error, but not always. We must check that we wrote the entire file!

Note that unlike write, fwrite's description according to POSIX does not mention returning a negative type at all. Nor does it say you can retry unlike write.

Finally, with write, we need to check less than 0, not 0, as 0 is a valid return and does not mean an error.

2 weeks agoMerge pull request #2678 from mostynb/zstd_filter_checksum
Tim Kientzle [Fri, 20 Jun 2025 16:32:51 +0000 (09:32 -0700)] 
Merge pull request #2678 from mostynb/zstd_filter_checksum

Enable Zstandard's checksum feature in the zstd write filter

2 weeks agoEnable Zstandard's checksum feature in the zstd write filter 2678/head
Mostyn Bramley-Moore [Fri, 20 Jun 2025 12:39:28 +0000 (14:39 +0200)] 
Enable Zstandard's checksum feature in the zstd write filter

Note that this is not enabled when writing .zip or .7z archive formats,
because they already use their own checksums.

Implements #2675.

2 weeks agoMerge pull request #2677 from AZero13/fwrite
Tim Kientzle [Thu, 19 Jun 2025 23:12:26 +0000 (16:12 -0700)] 
Merge pull request #2677 from AZero13/fwrite

Change error message from "fwrite function failed" to "write function failed"

2 weeks agoChange error message from "fwrite function failed" to "write function failed" 2677/head
Rose [Thu, 19 Jun 2025 16:00:23 +0000 (12:00 -0400)] 
Change error message from "fwrite function failed" to "write function failed"

We are checking the return value from write, not fwrite, so this message is wrong.

2 weeks agoMerge pull request #2676 from danyeaw/fix-pkgconf-path
Tim Kientzle [Thu, 19 Jun 2025 15:20:43 +0000 (08:20 -0700)] 
Merge pull request #2676 from danyeaw/fix-pkgconf-path

Fix .pc location when CMAKE_INSTALL_LIBDIR not set

2 weeks agoFix .pc location when CMAKE_INSTALL_LIBDIR not set 2676/head
Dan Yeaw [Thu, 19 Jun 2025 01:27:04 +0000 (21:27 -0400)] 
Fix .pc location when CMAKE_INSTALL_LIBDIR not set

2 weeks agoError related to restrict keyword supressed for older vs compiler 2687/head
Hemant [Wed, 18 Jun 2025 19:05:23 +0000 (14:05 -0500)] 
Error related to restrict keyword supressed for older vs compiler

2 weeks agoError related to restrict keyword supressed for older vs compiler
Hemant [Wed, 18 Jun 2025 18:51:00 +0000 (13:51 -0500)] 
Error related to restrict keyword supressed for older vs compiler

3 weeks agoMerge pull request #2659 from stoeckmann/chld
Martin Matuška [Thu, 12 Jun 2025 08:59:43 +0000 (10:59 +0200)] 
Merge pull request #2659 from stoeckmann/chld

Improve filter process handling

3 weeks agoMerge pull request #2669 from benoit-pierre/pr/minor_test_related_tweaks
Martin Matuška [Thu, 12 Jun 2025 08:57:17 +0000 (10:57 +0200)] 
Merge pull request #2669 from benoit-pierre/pr/minor_test_related_tweaks

minor test related tweaks

3 weeks agoMerge pull request #2663 from stoeckmann/filename_errpath
Martin Matuška [Thu, 12 Jun 2025 08:56:32 +0000 (10:56 +0200)] 
Merge pull request #2663 from stoeckmann/filename_errpath

open_filename: Free memory on error paths

3 weeks agoMerge pull request #2665 from stoeckmann/read_data_sparse
Martin Matuška [Thu, 12 Jun 2025 08:54:08 +0000 (10:54 +0200)] 
Merge pull request #2665 from stoeckmann/read_data_sparse

archive_read_data: Handle sparse holes at end of file correctly

3 weeks agoMerge pull request #2668 from stoeckmann/7z_oob
Martin Matuška [Thu, 12 Jun 2025 08:51:45 +0000 (10:51 +0200)] 
Merge pull request #2668 from stoeckmann/7z_oob

7zip: Fix out of boundary access

3 weeks agoarchive_cryptor_private.h: check message digest functions are enabled for windows 2673/head
Raman Shyshniou [Thu, 12 Jun 2025 00:22:47 +0000 (00:22 +0000)] 
archive_cryptor_private.h: check message digest functions are enabled for windows

4 weeks agotest_utils: factorize `canProg` implementations 2669/head
Benoit Pierre [Sat, 7 Jun 2025 22:04:24 +0000 (00:04 +0200)] 
test_utils: factorize `canProg` implementations

4 weeks agotest_utils: fix `canRunCommand` implementation
Benoit Pierre [Sat, 7 Jun 2025 22:04:23 +0000 (00:04 +0200)] 
test_utils: fix `canRunCommand` implementation

Do not unconditionally cache the result of the first call (and
reused it for subsequent calls). Thankfully, the function is
only called once.

4 weeks agoopen_filename: Free memory on error paths 2663/head
Tobias Stoeckmann [Tue, 3 Jun 2025 15:51:28 +0000 (17:51 +0200)] 
open_filename: Free memory on error paths

If opening a filename fails, make sure that allocated memory which is
not inserted into any remaining structure is freed.

Fixes https://github.com/libarchive/libarchive/issues/1949

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 weeks ago7zip: Fix out ouf boundary read in ELF detection 2668/head
Tobias Stoeckmann [Thu, 5 Jun 2025 19:38:43 +0000 (21:38 +0200)] 
7zip: Fix out ouf boundary read in ELF detection

Make sure that the string table size is not smaller than 6 (and also
not larger than SIZE_MAX for better 32 bit support).

Such small values would lead to a large loop limit which either leads to
a crash or wrong detection of a ".data" string in possibly uninitialized
memory.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 weeks ago7zip: Increase minimum ELF header length
Tobias Stoeckmann [Thu, 5 Jun 2025 19:36:23 +0000 (21:36 +0200)] 
7zip: Increase minimum ELF header length

The 64 bit format requires at least 63 bytes, so increase this limit.
Such small binaries most likely don't contain 7zip data anyway.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 weeks agoMerge pull request #2662 from stoeckmann/set_format_strcpy
Tim Kientzle [Wed, 4 Jun 2025 12:58:32 +0000 (05:58 -0700)] 
Merge pull request #2662 from stoeckmann/set_format_strcpy

archive_read_set_format: Remove strcpy calls

4 weeks agoarchive_read: Handle sparse holes at end of file 2665/head
Tobias Stoeckmann [Tue, 3 Jun 2025 20:00:13 +0000 (22:00 +0200)] 
archive_read: Handle sparse holes at end of file

If a sparse hole is located at the end of an entry, then the tar
parser returns ARCHIVE_EOF while updating the offset where 0 bytes of
data will follow.

If archive_read_data encounters such an ARCHIVE_EOF return value, it
has to recheck if the offsets (data offset and output offset) still
match. If they do not match, it has to keep filling 0 bytes.

This changes assumes that it's okay to call archive_read_data_block
again after an EOF. As far as I understood the parsers so far, this
should be okay, since it's always ARCHIVE_EOF afterwards.

Fixes https://github.com/libarchive/libarchive/issues/1194

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 weeks agorar: Do not forcefully set offset to unpacked size
Tobias Stoeckmann [Tue, 3 Jun 2025 19:59:05 +0000 (21:59 +0200)] 
rar: Do not forcefully set offset to unpacked size

If an entry reaches its end of file, the offset is not necessarily
the same as unp_size. This is especially true for links which have
a "0 size body" even though the unpacked size is not 0.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 weeks agowarc: Ignore separator when reaching end of entry
Tobias Stoeckmann [Tue, 3 Jun 2025 19:57:42 +0000 (21:57 +0200)] 
warc: Ignore separator when reaching end of entry

When _warc_read encounters end of entry, it adds 4 bytes to the last
offset for \r\n\r\n separator, which is never written. Ignore these
bytes since they are not part of the returned entry.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 weeks agoxar: End with entry offset, not archive offset
Tobias Stoeckmann [Tue, 3 Jun 2025 19:57:05 +0000 (21:57 +0200)] 
xar: End with entry offset, not archive offset

If xar_read_data has no further data, set offset to end of entry,
not to total size of parsed archive so far.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 weeks agoFix a memory leak if write callback error early 2664/head
Federico Giovanardi [Tue, 3 Jun 2025 16:24:35 +0000 (18:24 +0200)] 
Fix a memory leak if write callback error early

4 weeks agoarchive_read_set_format: Remove strcpy calls 2662/head
Tobias Stoeckmann [Tue, 3 Jun 2025 15:43:27 +0000 (17:43 +0200)] 
archive_read_set_format: Remove strcpy calls

The string constants can be used directly for comparison, which makes
this code robust against future changes which could lead to names being
longer than str could hold on stack.

Also removes around 100 bytes from compiled library (with gcc 15).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 weeks agoSkip zlib tests if support is missing 2658/head
Tobias Stoeckmann [Tue, 3 Jun 2025 15:24:30 +0000 (17:24 +0200)] 
Skip zlib tests if support is missing

If zlib is not supported, do not run tests to avoid false positives.

Also adjust tests to support latest gzip versions (1.10+) which store
less information for improved reproducibility. The gzip binary is
used as a fallback if zlib is not available.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 weeks agoSkip lzma test if support is missing
Tobias Stoeckmann [Mon, 2 Jun 2025 19:42:39 +0000 (21:42 +0200)] 
Skip lzma test if support is missing

If lzma is not supported, do not run tests to avoid false positives.

Fixes https://github.com/libarchive/libarchive/issues/2647

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 weeks agoSkip KOI8 conversion test if support is missing
Tobias Stoeckmann [Mon, 2 Jun 2025 19:41:09 +0000 (21:41 +0200)] 
Skip KOI8 conversion test if support is missing

If a unix system has no iconv support, the best effort function will
be unable to convert KOI8 to UTF-8. Skip the test if such support is
missing.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 weeks agounzip: Pass test if encryption support is missing
Tobias Stoeckmann [Mon, 2 Jun 2025 19:38:11 +0000 (21:38 +0200)] 
unzip: Pass test if encryption support is missing

If no encryption support exists, the -P option will always fail.
"Skip" the test by making sure that there really is no encryption
support according to libarchive functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 weeks agozip: Better detect no encryption support
Tobias Stoeckmann [Mon, 2 Jun 2025 19:20:58 +0000 (21:20 +0200)] 
zip: Better detect no encryption support

Some functions might return -1 in case of library error. Use an
own return value if a stub function was used for better error
messages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
4 weeks agoMerge pull request #2660 from kevans91/ke/fix-fortify
Tim Kientzle [Tue, 3 Jun 2025 13:02:09 +0000 (06:02 -0700)] 
Merge pull request #2660 from kevans91/ke/fix-fortify

libarchive/test: fix build when memcpy() is a macro

4 weeks agolibarchive/test: fix build when memcpy() is a macro 2660/head
Kyle Evans [Tue, 3 Jun 2025 02:43:28 +0000 (21:43 -0500)] 
libarchive/test: fix build when memcpy() is a macro

After importing the latest libarchive into FreeBSD, Shawn Webb @
HardenedBSD noted that the test build is broken when FORTIFY_SOURCE=2
while building the base system.  Braced initializer lists are a special
case that need some extra fun parentheses when we're dealing with the
preprocessor.

While it's not a particularly common setup, the extra parentheses don't
really hurt readability all that much so it's worth fixing for wider
compatibility.

Fixes: libarchive/libarchive#2657
5 weeks agotools: Enforce default handling of SIGCHLD 2659/head
Tobias Stoeckmann [Mon, 2 Jun 2025 21:29:49 +0000 (23:29 +0200)] 
tools: Enforce default handling of SIGCHLD

Ignoring SIGCHLD gets passed to child processes. Doing that has
influence on waitpid, namely that zombie processes won't be
created. This means that a status can never be read.

We can't enforce this in library, but libarchive's tools can be
protected against this by enforcing default handling.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agoUnify reader and writer filter process handling
Tobias Stoeckmann [Mon, 2 Jun 2025 21:28:26 +0000 (23:28 +0200)] 
Unify reader and writer filter process handling

Use pid_t since waitpid returns a pid_t. Also check for a negative
return value in writer as well to avoid reading the possibly
unitialized status value.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agowindows: close child process handle only once
Tobias Stoeckmann [Mon, 2 Jun 2025 21:23:05 +0000 (23:23 +0200)] 
windows: close child process handle only once

Calling CloseHandle multiple times for the same handle can lead to
exceptions while debugging according to documentation.

Mimic the waitpid handling for success cases to behave more like the
Unix version which would "reap the zombie".

Doing this for an unsuccessful call is off, but the loop is never
entered again, so I guess it's okay and worth it to reduce the amount
of Windows specific definitions in source files.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agowindows: Preserve GetExitCodeProcess error
Tobias Stoeckmann [Mon, 2 Jun 2025 21:21:26 +0000 (23:21 +0200)] 
windows: Preserve GetExitCodeProcess error

If the waitpid version for Windows fails, preserve the error code and
avoid overwriting it with a possible CloseHandle error.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agoMerge pull request #2655 from mmatuska/fix/setclocale
Tim Kientzle [Sun, 1 Jun 2025 23:04:49 +0000 (16:04 -0700)] 
Merge pull request #2655 from mmatuska/fix/setclocale

test_utils/test_main.c: satisfy -Wstrict-prototypes

5 weeks agotest_utils/test_main.c: satisfy -Wstrict-prototypes 2655/head
Martin Matuska [Sun, 1 Jun 2025 21:35:05 +0000 (23:35 +0200)] 
test_utils/test_main.c: satisfy -Wstrict-prototypes

5 weeks agoMerge pull request #2627 from heirecka/do-not-hard-code-pkg-config
Martin Matuška [Sat, 31 May 2025 19:40:04 +0000 (21:40 +0200)] 
Merge pull request #2627 from heirecka/do-not-hard-code-pkg-config

Use PKG_CONFIG instead of hard-coded pkg-config

5 weeks agoMerge pull request #2643 from stoeckmann/tar_pax_sparse
Martin Matuška [Sat, 31 May 2025 19:31:14 +0000 (21:31 +0200)] 
Merge pull request #2643 from stoeckmann/tar_pax_sparse

tar: Handle extra bytes after sparse entries

5 weeks agoMerge pull request #2652 from stoeckmann/wstring_ensure
Tim Kientzle [Sat, 31 May 2025 14:16:07 +0000 (07:16 -0700)] 
Merge pull request #2652 from stoeckmann/wstring_ensure

Check archive_wstring_ensure return value

5 weeks agoAlways check archive_wstring_ensure return value 2652/head
Tobias Stoeckmann [Sat, 31 May 2025 09:33:07 +0000 (11:33 +0200)] 
Always check archive_wstring_ensure return value

Memory allocation might fail, so check if it was successful.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agowrite disk windows: Release memory on error paths
Tobias Stoeckmann [Sat, 31 May 2025 09:31:50 +0000 (11:31 +0200)] 
write disk windows: Release memory on error paths

Free wsp in case of out of memory condition.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agoiso9660: Check another archive_string_ensure result
Tobias Stoeckmann [Sat, 31 May 2025 07:46:17 +0000 (09:46 +0200)] 
iso9660: Check another archive_string_ensure result

Missed one unchecked archive_string_ensure in the previous commit.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agoMerge pull request #2651 from stoeckmann/string_ensure_check
Tim Kientzle [Sat, 31 May 2025 02:50:25 +0000 (19:50 -0700)] 
Merge pull request #2651 from stoeckmann/string_ensure_check

Always check archive_string_ensure return value

5 weeks agoMerge pull request #2648 from stoeckmann/test_en_us
Tim Kientzle [Sat, 31 May 2025 02:35:44 +0000 (19:35 -0700)] 
Merge pull request #2648 from stoeckmann/test_en_us

test_utils: Enforce C locale for all tests

5 weeks agoMerge pull request #2650 from stoeckmann/string_sort
Tim Kientzle [Sat, 31 May 2025 02:33:34 +0000 (19:33 -0700)] 
Merge pull request #2650 from stoeckmann/string_sort

archive_utility_string_sort: Use qsort directly

5 weeks agoAlways check archive_string_ensure return value 2651/head
Tobias Stoeckmann [Fri, 30 May 2025 21:41:21 +0000 (23:41 +0200)] 
Always check archive_string_ensure return value

Memory allocation might fail, so check if it was successful.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agoRemove archive_utility_string_sort with 4.0.0 2650/head
Tobias Stoeckmann [Fri, 30 May 2025 15:41:26 +0000 (17:41 +0200)] 
Remove archive_utility_string_sort with 4.0.0

The archive_utility_string_sort function won't be part of the 4.0.0 API
anymore. No users were found and such a task should be done outside of
the library.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agoarchive_utility_string_sort: Use qsort directly
Tobias Stoeckmann [Thu, 29 May 2025 16:19:47 +0000 (18:19 +0200)] 
archive_utility_string_sort: Use qsort directly

The utility function "archive_utility_string_sort" is a custom qsort
implementation. Since qsort is specified in C11 and POSIX.1-2008
which libarchive is based on, use system's qsort directly.

The function is not used directly in libarchive, so this is a good
way to save around 500 bytes in resulting library without breaking
compatibility for any user of this function (none found).

Also allows more than UINT_MAX entries which previously were limited
by data type and (way earlier) due to recursion.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agotest_list_item: Do not modify LC_TIME 2648/head
Tobias Stoeckmann [Fri, 30 May 2025 15:33:19 +0000 (17:33 +0200)] 
test_list_item: Do not modify LC_TIME

Test cases already get a C locale, which is sufficient for this test.
IF LC_TIME was not previously set, the used en_US.UTF-8 would stay
as an environment variable, possibly affecting other test cases.
Since en_US.UTF-8 is not guaranteed to be available, C is a better
choice.

Fixes https://github.com/libarchive/libarchive/issues/2560

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agotest_utils: Reset all locale related entries
Tobias Stoeckmann [Fri, 30 May 2025 15:32:02 +0000 (17:32 +0200)] 
test_utils: Reset all locale related entries

Reset current locale settings through setlocale and also all
environment variables which might affect test cases which
spawn children through systemf which in turn would call setlocale
on their own, e.g. bsdtar.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agoMerge pull request #2634 from stoeckmann/tar_neg_time
Tim Kientzle [Fri, 30 May 2025 00:31:28 +0000 (17:31 -0700)] 
Merge pull request #2634 from stoeckmann/tar_neg_time

tar: Support negative time values with pax

5 weeks agoMerge pull request #2649 from stoeckmann/compress_recursion
Tim Kientzle [Thu, 29 May 2025 23:37:44 +0000 (16:37 -0700)] 
Merge pull request #2649 from stoeckmann/compress_recursion

compress: Prevent call stack overflow

5 weeks agocompress: Prevent call stack overflow 2649/head
Tobias Stoeckmann [Thu, 29 May 2025 13:07:02 +0000 (15:07 +0200)] 
compress: Prevent call stack overflow

Explicitly use goto to turn a recursive call into an iterative one.
Most compilers do this on their own with default settings, but MSVC
with default settings would create a binary which actually performs
recursive calls.

Fixes call stack overflow in binaries compiled with low optimization.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agoMerge pull request #2642 from stoeckmann/seek_regress
Tim Kientzle [Wed, 28 May 2025 03:55:15 +0000 (20:55 -0700)] 
Merge pull request #2642 from stoeckmann/seek_regress

Fix FILE_skip regression

5 weeks agoMerge pull request #2644 from stoeckmann/tar_neg_size
Tim Kientzle [Wed, 28 May 2025 03:52:36 +0000 (20:52 -0700)] 
Merge pull request #2644 from stoeckmann/tar_neg_size

tar: Always treat negative sizes as error

5 weeks agoMerge pull request #2645 from stoeckmann/tar_formatter
Tim Kientzle [Wed, 28 May 2025 03:43:46 +0000 (20:43 -0700)] 
Merge pull request #2645 from stoeckmann/tar_formatter

tar: Fix archive_set_error formatters

5 weeks agoMerge pull request #2646 from stoeckmann/sparse32
Tim Kientzle [Wed, 28 May 2025 03:41:19 +0000 (20:41 -0700)] 
Merge pull request #2646 from stoeckmann/sparse32

tar: Handle many sparse comments on 32 bit systems

5 weeks agotar: Handle many sparse comments on 32 bit systems 2646/head
Tobias Stoeckmann [Tue, 27 May 2025 19:08:55 +0000 (21:08 +0200)] 
tar: Handle many sparse comments on 32 bit systems

The sparse 1.0 parser skips lines with comments. The amount of skipped
bytes is stored in a ssize_t variable, although common 32 bit systems
allow files larger than 4 GB.

Gracefully handle files with more than 2 GB bytes full of comments to
prevent integer truncations.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agotar: Fix archive_set_error formatters 2645/head
Tobias Stoeckmann [Tue, 27 May 2025 18:45:55 +0000 (20:45 +0200)] 
tar: Fix archive_set_error formatters

Use correct formatters and casts with newly introduced ll
length modifier.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agotar: Always treat negative sizes as error 2644/head
Tobias Stoeckmann [Tue, 27 May 2025 18:30:01 +0000 (20:30 +0200)] 
tar: Always treat negative sizes as error

If a pax global header specifies a negative size, it is possible to
reduce variable `unconsumed` by 512 bytes, leading to a re-reading
of the pax global header. Fortunately the loop verifies that only one
global header per entry is allowed, leading to a later ARCHIVE_FATAL.

Avoid any form of negative size handling and fail early.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agotar: Handle extra bytes after sparse entries 2643/head
Tobias Stoeckmann [Tue, 27 May 2025 17:57:05 +0000 (19:57 +0200)] 
tar: Handle extra bytes after sparse entries

Skip all entry bytes after sparse entries were encountered. This matches
GNU tar behavior.

I have adjusted (and fixed) the existing test case for this. The test
case test_read_format_gtar_sparse_skip_entry did not work with GNU tar.

In #2558 it was explained that the pax size always overrides the header
size (correct). Since the pax size in the test case was way larger than
the actual entry bytes in archive, GNU tar choke on the test file.

The libarchive parser did not skip any bytes not already read due to
references by sparse entries, so the huge pax size was not detected.

By adjusting the test case to have a leftover byte (only 3 bytes are
referenced through sparse entry now, leaving one extra byte) with a
correct pax size and an invalid header size (after all it is overridden
by pax size), GNU tar works and libarchive gets off its 512 byte
alignment, not being able to read the next entry.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
5 weeks agoFix FILE_skip regression 2642/head
Tobias Stoeckmann [Tue, 27 May 2025 15:09:12 +0000 (17:09 +0200)] 
Fix FILE_skip regression

The fseek* family of functions return 0 on success, not the new offset.
This is only true for lseek.

Fixes https://github.com/libarchive/libarchive/issues/2641
Fixes dcbf1e0ededa95849f098d154a25876ed5754bcf

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 weeks agoMerge pull request #2640 from robUx4/xml-uuid
Tim Kientzle [Mon, 26 May 2025 16:06:47 +0000 (09:06 -0700)] 
Merge pull request #2640 from robUx4/xml-uuid

[cmake] add uuid library when using xmllite

6 weeks ago[cmake] add uuid library when using xmllite 2640/head
Steve Lhomme [Mon, 26 May 2025 08:44:49 +0000 (10:44 +0200)] 
[cmake] add uuid library when using xmllite

Consecutive to 16fd043f51d911b106f2a7834ad8f08f65051977
IID_ISequentialStream is required by the code.
This GUID is defined in uuid.lib or libuuid.a in mingw-w64. It is required
to link with that library to get the definition of the GUID. Some toolchains
add it by default but not all.

6 weeks agoMerge pull request #2637 from stoeckmann/pax_nl
Tim Kientzle [Sun, 25 May 2025 23:22:59 +0000 (16:22 -0700)] 
Merge pull request #2637 from stoeckmann/pax_nl

tar: Keep block alignment after pax error

6 weeks agoMerge pull request #2639 from stoeckmann/sprintf_ll
Tim Kientzle [Sun, 25 May 2025 23:19:38 +0000 (16:19 -0700)] 
Merge pull request #2639 from stoeckmann/sprintf_ll

Add ll length modifier to archive_string_vsprintf

6 weeks agoAdd ll length modifier to archive_string_vsprintf 2639/head
Tobias Stoeckmann [Sun, 25 May 2025 12:26:25 +0000 (14:26 +0200)] 
Add ll length modifier to archive_string_vsprintf

Some error messages already use the ll length modifier, which results
in raw formatter output, i.e. "%lld" instead of a number.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 weeks agotar: Keep block alignment after pax error 2637/head
Tobias Stoeckmann [Sun, 25 May 2025 10:03:55 +0000 (12:03 +0200)] 
tar: Keep block alignment after pax error

If a pax attribute has a 0 length value and no newline, the tar reader
gets out of sync with block alignment.

This happens because the pax parser assumes that variable value_length
(which includes the terminating newline) is at least 1. To get the
real value length, 1 is subtracted. This result is subtracted from
extsize, which in this case would lead to `extsize -= -1`, i.e.
the remaining byte count is increased.

Such an unexpected calculation leads to an off-by-one when skipping
to the next block. In supplied test case, bsdtar complains that the
checksum of the next block is wrong. Since the tar parser was not
properly 512 bytes aligned, this is no surprise.

Gracefully handle such a case like GNU tar does and warn the user that
an invalid attribute has been encountered.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 weeks agoMerge pull request #2636 from zhaofengli/reset-header-state-after-mac-metadata
Tim Kientzle [Sun, 25 May 2025 00:18:00 +0000 (17:18 -0700)] 
Merge pull request #2636 from zhaofengli/reset-header-state-after-mac-metadata

tar: Reset accumulated header state after reading macOS metadata blob

6 weeks agoAdd test for macOS metadata reading in tar archives 2636/head
Zhaofeng Li [Sat, 24 May 2025 22:40:08 +0000 (16:40 -0600)] 
Add test for macOS metadata reading in tar archives

Signed-off-by: Zhaofeng Li <hello@zhaofeng.li>
6 weeks agotar: Reset accumulated header state after reading macOS metadata blob
Zhaofeng Li [Sat, 24 May 2025 19:45:18 +0000 (13:45 -0600)] 
tar: Reset accumulated header state after reading macOS metadata blob

AppleDouble extension entries are present as separate files immediately
preceding the corresponding real files. In libarchive, we process the
entire metadata file (headers + data) as if it were a header in the real
file. However, the code forgets to reset the accumulated header state
before parsing the real file's headers. In one code path, this causes
the metadata file's name to be used as the real file's name.

Specifically, this can be triggered with a tar containing two files:

1. A file named `._badname` with pax header containing the `path` attribute
2. A file named `goodname` _with_ a pax header but _without_ the `path` attribute

libarchive will list one file, `._badname` containing the data of `goodname`.

This code is pretty brittle and we really should let the client deal with
it :(

Fixes #2510.

Signed-off-by: Zhaofeng Li <hello@zhaofeng.li>
6 weeks agoMerge pull request #2630 from stoeckmann/wincrypt_casts
Tim Kientzle [Sat, 24 May 2025 17:45:57 +0000 (10:45 -0700)] 
Merge pull request #2630 from stoeckmann/wincrypt_casts

Fix archive_wincrypt_version

6 weeks agoMerge pull request #2633 from stoeckmann/match_cleanup
Tim Kientzle [Sat, 24 May 2025 17:37:02 +0000 (10:37 -0700)] 
Merge pull request #2633 from stoeckmann/match_cleanup

archive_match: Simplify and clean up code

6 weeks agotar: Support negative time values with pax 2634/head
Tobias Stoeckmann [Sat, 24 May 2025 12:47:20 +0000 (14:47 +0200)] 
tar: Support negative time values with pax

Pax extended headers may specify negative time values for files older
than the epoch.

Adjust the code to clear values to 0.0 more often and set ps to
INT64_MIN to have a proper error specifier, because the parser does
not allow anything below -INT64_MAX.

Fixes https://github.com/libarchive/libarchive/issues/2562

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 weeks agoMerge pull request #2632 from stoeckmann/cygwin_definition
Tim Kientzle [Sat, 24 May 2025 17:23:28 +0000 (10:23 -0700)] 
Merge pull request #2632 from stoeckmann/cygwin_definition

Prefer __CYGWIN__ over CYGWIN definition

6 weeks agoarchive_match: Fix whitespaces, style 2633/head
Tobias Stoeckmann [Sat, 24 May 2025 10:35:36 +0000 (12:35 +0200)] 
archive_match: Fix whitespaces, style

Adjust whitespaces to match file layout and add a full stop to
a comment to match others.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 weeks agoarchive_match: Use correct data type for iterator
Tobias Stoeckmann [Sat, 24 May 2025 10:29:36 +0000 (12:29 +0200)] 
archive_match: Use correct data type for iterator

Iterating over a size_t with unsigned could lead to an endless loop
while adding uid/gid to a list which already counts 4 billion
entries.

I doubt that this can ever happen, given that the routines become
very slow with insertions, but better be safe than sorry.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 weeks agoarchive_match: Allow arbitrarily long match lists
Tobias Stoeckmann [Sat, 24 May 2025 10:28:08 +0000 (12:28 +0200)] 
archive_match: Allow arbitrarily long match lists

Turn unmatched_count into a size_t to support as many entries as
possible on the machine.

If more than INT_MAX entries are not matched, truncate the result
of archive_match_path_unmatched_inclusions for external callers.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 weeks agoarchive_match: Remove unneeded count fields
Tobias Stoeckmann [Sat, 24 May 2025 10:24:49 +0000 (12:24 +0200)] 
archive_match: Remove unneeded count fields

The count fields are merely used to check if a list is empty or not.
A check for first being not NULL is sufficient and is already in
place while iterating over the linked elements (count is not used).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 weeks agoarchive_match: Set red/black tree operations once
Tobias Stoeckmann [Sat, 24 May 2025 10:07:04 +0000 (12:07 +0200)] 
archive_match: Set red/black tree operations once

The operations for key and node comparison depend on the platform
libarchive is compiled for. Since these values do not change
during runtime, set them only once during initialisation.

Further simplify the code by declaring only one "rb_ops" with
required functions based on platform.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
6 weeks agoPrefer __CYGWIN__ over CYGWIN definition 2632/head
Tobias Stoeckmann [Sat, 24 May 2025 09:37:26 +0000 (11:37 +0200)] 
Prefer __CYGWIN__ over CYGWIN definition

The cygwin FAQ states that __CYGWIN__ is defined when building for a
Cygwin environment. Only a few test files check (inconsistently) for
CYGWIN, so adjust them to the recommended __CYGWIN__ definition.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>