]> git.ipfire.org Git - thirdparty/libarchive.git/log
thirdparty/libarchive.git
4 weeks 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

5 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

5 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.

5 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

5 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.

5 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"

5 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.

5 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

6 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

6 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

6 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

6 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

6 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

6 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

7 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

7 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.

7 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>
7 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>
7 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>
8 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

8 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>
8 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>
8 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>
8 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>
8 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>
8 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

8 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
8 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>
8 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>
8 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>
8 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>
8 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

8 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

8 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

8 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

8 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

2 months 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>
2 months 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>
2 months 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>
2 months 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

2 months 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

2 months 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

2 months 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>
2 months 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>
2 months 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>
2 months 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>
2 months 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>
2 months 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

2 months 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

2 months 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>
2 months 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

2 months 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

2 months 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

2 months 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

2 months 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>
2 months 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>
2 months 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>
2 months 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>
2 months 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>
2 months 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

2 months 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.

2 months 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

2 months 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

2 months 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>
2 months 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>
2 months 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

2 months 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>
2 months 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>
2 months 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

2 months 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

2 months 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>
2 months 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

2 months 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>
2 months 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>
2 months 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>
2 months 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>
2 months 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>
2 months 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>
2 months agoMerge pull request #2631 from stoeckmann/configure_windows
Tim Kientzle [Sat, 24 May 2025 02:58:02 +0000 (19:58 -0700)] 
Merge pull request #2631 from stoeckmann/configure_windows

configure.ac: Improve Windows version detection

2 months agoMerge pull request #2509 from tesap/install-lib-dir
Tim Kientzle [Sat, 24 May 2025 02:57:14 +0000 (19:57 -0700)] 
Merge pull request #2509 from tesap/install-lib-dir

Make installation lib dir depend on CMAKE_INSTALL_LIBDIR variable

2 months agoMerge pull request #2629 from mmatuska/fix/versiontest
Tim Kientzle [Sat, 24 May 2025 02:39:00 +0000 (19:39 -0700)] 
Merge pull request #2629 from mmatuska/fix/versiontest

tests: accept underscore in arbitrary third-party version strings

2 months agoSet ARCHIVE_CRYPTOR_USE_WINCRYPT for WinCrypt 2630/head
Tobias Stoeckmann [Fri, 23 May 2025 17:33:53 +0000 (19:33 +0200)] 
Set ARCHIVE_CRYPTOR_USE_WINCRYPT for WinCrypt

If WinCrypt is used, actually set ARCHIVE_CRYPTOR_USE_WINCRYPT
for version details output.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months agoarchive_version_details.c: Drop ARCHIVE_DIGEST_*
Tobias Stoeckmann [Fri, 23 May 2025 17:27:08 +0000 (19:27 +0200)] 
archive_version_details.c: Drop ARCHIVE_DIGEST_*

These definitions are never available and are supposedly a leftover of
a work in progress.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months agoconfigure.ac: Improve Windows version detection 2631/head
Tobias Stoeckmann [Fri, 23 May 2025 17:22:06 +0000 (19:22 +0200)] 
configure.ac: Improve Windows version detection

Include windows.h for better windows version detection.

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

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months agoFix archive_wincrypt_version compilation
Tobias Stoeckmann [Fri, 23 May 2025 16:59:05 +0000 (18:59 +0200)] 
Fix archive_wincrypt_version compilation

Cast address of "version" to BYTE pointer for CryptGetProvParam.
Fix "major" variable assignment for picky compilers like MSVC.

The "length" variable is an in/out variable. It must be set to the size
of available memory within "version". Right now it is undefined behavior
and 0 would crash during runtime.

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

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months agotests: accept underscore in arbitrary third-party version strings 2629/head
Martin Matuska [Fri, 23 May 2025 11:19:21 +0000 (13:19 +0200)] 
tests: accept underscore in arbitrary third-party version strings

Fixes #2626

2 months agoUse PKG_CONFIG instead of hard-coded pkg-config 2627/head
Heiko Becker [Tue, 20 May 2025 22:44:50 +0000 (00:44 +0200)] 
Use PKG_CONFIG instead of hard-coded pkg-config

2 months agoMerge pull request #2624 from mmatuska/feat/390dev
Tim Kientzle [Tue, 20 May 2025 14:55:26 +0000 (07:55 -0700)] 
Merge pull request #2624 from mmatuska/feat/390dev

Libarchive 3.9.0dev

2 months agoLibarchive 3.9.0dev 2624/head
Martin Matuska [Tue, 20 May 2025 08:26:29 +0000 (10:26 +0200)] 
Libarchive 3.9.0dev

2 months agoCI: Bump the all-actions group across 1 directory with 4 updates (#2623)
dependabot[bot] [Tue, 20 May 2025 08:19:56 +0000 (10:19 +0200)] 
CI: Bump the all-actions group across 1 directory with 4 updates (#2623)

Bumps the all-actions group with 4 updates:
`actions/checkout` from 4.2.1 to 4.2.2
`actions/upload-artifact` from 4.4.3 to 4.6.2
`github/codeql-action` from 3.26.12 to 3.28.18
`ossf/scorecard-action` from 2.4.0 to 2.4.1

2 months agoAdd some more error checking to shell scripts (#2617)
Mostyn Bramley-Moore [Tue, 20 May 2025 08:14:17 +0000 (10:14 +0200)] 
Add some more error checking to shell scripts (#2617)

Exit immediately if a command exits with a non-zero status, and treat
unset variables as an error when substituting.

2 months agoMerge pull request #2612 from AZero13/okay-what
Tim Kientzle [Tue, 20 May 2025 02:39:10 +0000 (19:39 -0700)] 
Merge pull request #2612 from AZero13/okay-what

Fatal if field[0].start is null

2 months agoMerge pull request #2622 from AZero13/calculate-size
Tim Kientzle [Tue, 20 May 2025 02:38:04 +0000 (19:38 -0700)] 
Merge pull request #2622 from AZero13/calculate-size

Calculate size of arrays instead of assuming they are always 6

2 months agoMerge pull request #2621 from AZero13/redundant-s
Tim Kientzle [Tue, 20 May 2025 02:36:57 +0000 (19:36 -0700)] 
Merge pull request #2621 from AZero13/redundant-s

*s != '\0' is redundant

2 months agoMerge pull request #2619 from AZero13/patch-2
Tim Kientzle [Tue, 20 May 2025 02:34:24 +0000 (19:34 -0700)] 
Merge pull request #2619 from AZero13/patch-2

days should be a long type

2 months agoMerge pull request #2618 from AZero13/patch-1
Tim Kientzle [Tue, 20 May 2025 02:32:32 +0000 (19:32 -0700)] 
Merge pull request #2618 from AZero13/patch-1

Label error and errorx as __LA_NORETURN

2 months agoCalculate size of arrays instead of assuming they are always 6 2622/head
Rose [Mon, 19 May 2025 19:19:57 +0000 (15:19 -0400)] 
Calculate size of arrays instead of assuming they are always 6

2 months ago*s != '\0' is redundant 2621/head
Rose [Mon, 19 May 2025 19:16:18 +0000 (15:16 -0400)] 
*s != '\0' is redundant

Not that this does anything to codegen probably, but it is still redundant.

2 months agoFatal if field[0].start or field[0].end is null 2612/head
Rose [Sat, 17 May 2025 23:35:22 +0000 (19:35 -0400)] 
Fatal if field[0].start or field[0].end is null

We should not get here, but given that the check exists, we should not let it happen if this is NULL because otherwise we just dereference it later on.

2 months agodays should be a long type 2619/head
AZero13 [Mon, 19 May 2025 17:39:32 +0000 (13:39 -0400)] 
days should be a long type

The difference in years is cast to a long and then multiplied by 365. The return value of the function is also a long.