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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

7 weeks agoLabel error and errorx as __LA_NORETURN 2618/head
AZero13 [Mon, 19 May 2025 17:35:19 +0000 (13:35 -0400)] 
Label error and errorx as __LA_NORETURN

This also prevents clang-tidy from reporting some false bugs.

7 weeks agoMerge pull request #2611 from zhaofengli/fix-iconv-pc
Tim Kientzle [Sun, 18 May 2025 22:44:48 +0000 (15:44 -0700)] 
Merge pull request #2611 from zhaofengli/fix-iconv-pc

autotools: Fix iconv issues in generated .pc file

7 weeks agoMerge pull request #2613 from mmatuska/fix/7zipsfx-2
Tim Kientzle [Sun, 18 May 2025 22:41:26 +0000 (15:41 -0700)] 
Merge pull request #2613 from mmatuska/fix/7zipsfx-2

7z: fix another out-of-bounds read in 7z SFX archive detection

7 weeks agoMerge pull request #2616 from mostynb/contrib_psota-benchmark_tcp_sh_bash
Tim Kientzle [Sun, 18 May 2025 22:26:17 +0000 (15:26 -0700)] 
Merge pull request #2616 from mostynb/contrib_psota-benchmark_tcp_sh_bash

contrib/psota-benchmark/tcp.sh is a bash script

7 weeks agoMerge pull request #2614 from AZero13/tar-2
Tim Kientzle [Sun, 18 May 2025 22:25:11 +0000 (15:25 -0700)] 
Merge pull request #2614 from AZero13/tar-2

Assign a result when failure happens

7 weeks agoMerge pull request #2600 from nvinson/master
Tim Kientzle [Sun, 18 May 2025 21:59:36 +0000 (14:59 -0700)] 
Merge pull request #2600 from nvinson/master

Copy ae digests to mtree_entry

7 weeks agoRemove long-unused travis CI script (#2615)
Mostyn Bramley-Moore [Sun, 18 May 2025 16:55:32 +0000 (18:55 +0200)] 
Remove long-unused travis CI script (#2615)

Support for travis CI was removed in 2019, this script hasn't been used
since.

7 weeks agocontrib/psota-benchmark/tcp.sh is a bash script 2616/head
Mostyn Bramley-Moore [Sun, 18 May 2025 10:58:27 +0000 (12:58 +0200)] 
contrib/psota-benchmark/tcp.sh is a bash script

I am unsure if this is still used, but it fails to run in Bourne shell.

7 weeks agoAssign a result when failure happens 2614/head
Rose [Sun, 18 May 2025 01:24:51 +0000 (21:24 -0400)] 
Assign a result when failure happens

In some places, result is checked even after failure, so let's assign a result.

7 weeks ago7z: fix another out-of-bounds read in 7z SFX archive detection 2613/head
Martin Matuska [Sun, 18 May 2025 00:40:05 +0000 (02:40 +0200)] 
7z: fix another out-of-bounds read in 7z SFX archive detection

When looping over program header entries (e_shnum)
we need to increment sec_tbl_offset by e_shentsize
and not by fixed values.

Fixes OSS-Fuzz issue 418349489

7 weeks agoMerge pull request #2610 from stoeckmann/string_int_size_t
Tim Kientzle [Sun, 18 May 2025 00:15:03 +0000 (17:15 -0700)] 
Merge pull request #2610 from stoeckmann/string_int_size_t

archive_string: Check values before casts

7 weeks agoautotools: Fix iconv issues in generated .pc file 2611/head
Zhaofeng Li [Sat, 17 May 2025 00:03:52 +0000 (18:03 -0600)] 
autotools: Fix iconv issues in generated .pc file

The goal is to make everyone (including msys2) happy.

Fixes #1766 and #1819.

Signed-off-by: Zhaofeng Li <hello@zhaofeng.li>
7 weeks agoMerge pull request #2609 from stoeckmann/safe_fprintf
Tim Kientzle [Sat, 17 May 2025 18:46:32 +0000 (11:46 -0700)] 
Merge pull request #2609 from stoeckmann/safe_fprintf

tar: Handle more edge cases in safe_fprintf

7 weeks agotest_utils/test_main.c: increase logfilename bf sz 2600/head
Nicholas Vinson [Sat, 17 May 2025 15:30:23 +0000 (11:30 -0400)] 
test_utils/test_main.c: increase logfilename bf sz

Increase logfilename buffer size from 64 to 256. This aligns the buffer
size with the size limits found in Windows and Linux.

7 weeks agoReplace struct ae_mset_digest with uint_least32_t
Nicholas Vinson [Tue, 13 May 2025 23:38:50 +0000 (19:38 -0400)] 
Replace struct ae_mset_digest with uint_least32_t

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
7 weeks agoCopy ae digests to mtree_entry
Nicholas Vinson [Sun, 13 Apr 2025 11:33:43 +0000 (07:33 -0400)] 
Copy ae digests to mtree_entry

    Copy ae digests to mtree_entry. This simplifies porting non-archive
    formats to archive formats while preserving supported message
    digests specifically in cases where recomputing digests is not
    viable.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
8 weeks agoarchive_string: Check values before casts 2610/head
Tobias Stoeckmann [Sat, 17 May 2025 08:36:47 +0000 (10:36 +0200)] 
archive_string: Check values before casts

The size_t to int conversion is especially required on Windows systems
to support their int-based functions. These variables should be properly
checked before casts. This avoids integer truncations with large
strings.

I prefer size_t over int for sizes and adjusted variables to size_t
where possible to avoid casts.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agoMerge pull request #2604 from mmatuska/fix/7zipsfx
Tim Kientzle [Fri, 16 May 2025 23:40:24 +0000 (16:40 -0700)] 
Merge pull request #2604 from mmatuska/fix/7zipsfx

7z: fix out-of-bounds read in 7z self extracting archive detection

8 weeks agoMerge pull request #2607 from zhaofengli/disallow-multiple-files-from
Tim Kientzle [Fri, 16 May 2025 22:49:16 +0000 (15:49 -0700)] 
Merge pull request #2607 from zhaofengli/disallow-multiple-files-from

bsdtar: Disallow multiple --files-from/-T options

8 weeks agotar: Make safe_fprintf more platform independent 2609/head
Tobias Stoeckmann [Fri, 16 May 2025 22:01:53 +0000 (00:01 +0200)] 
tar: Make safe_fprintf more platform independent

If vsnprintf fails with errno EOVERFLOW, the results are very platform
dependent but never useful. The implementation in glibc fills bytes with
blanks, FreeBSD fills them with zeros, OpenBSD and Windows set first
byte to '\0'.

Just stop processing and don't print anything, which makes it follow
the OpenBSD and Windows approach.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agotar: Fix safe_fprintf comment
Tobias Stoeckmann [Fri, 16 May 2025 21:25:42 +0000 (23:25 +0200)] 
tar: Fix safe_fprintf comment

The stack buffer is never used for out of memory messages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agotar: Support large strings in safe_fprintf
Tobias Stoeckmann [Fri, 16 May 2025 21:11:52 +0000 (23:11 +0200)] 
tar: Support large strings in safe_fprintf

The vsnprintf calls might return INT_MAX with very long strings.
Prevent a signed integer overflow when taking an additional nul
byte into account.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agotar: Always use correct length in safe_fprintf
Tobias Stoeckmann [Fri, 16 May 2025 21:08:59 +0000 (23:08 +0200)] 
tar: Always use correct length in safe_fprintf

If the format buffer shall not be further increased in size, the
length value mistakenly takes the terminating nul byte into account.

This is in contrast to a successful vsnprintf call.

Also use the correct string length if fallback to stack buffer is
required.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agotar: Clear safe_fprintf stack before usage
Tobias Stoeckmann [Fri, 16 May 2025 21:50:27 +0000 (23:50 +0200)] 
tar: Clear safe_fprintf stack before usage

The stack buffer is never cleared, which can become an issue depending
on vsnprintf implementation's behavior if -1 is returned. The code
would eventually fall back to stack buffer which might be not
nul terminated.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks ago7z: Free the file if compression-level option is invalid (#2608)
AZero13 [Fri, 16 May 2025 21:41:18 +0000 (17:41 -0400)] 
7z: Free the file if compression-level option is invalid (#2608)

Otherwise, the file is leaked.

8 weeks agobsdtar: Disallow multiple --files-from/-T options 2607/head
Zhaofeng Li [Fri, 16 May 2025 17:34:08 +0000 (11:34 -0600)] 
bsdtar: Disallow multiple --files-from/-T options

8 weeks agoMerge pull request #2606 from zhaofengli/parse-unix-epoch-date
Tim Kientzle [Fri, 16 May 2025 01:06:03 +0000 (18:06 -0700)] 
Merge pull request #2606 from zhaofengli/parse-unix-epoch-date

Support @-prefixed Unix epoch timestamps as date strings

8 weeks agoSupport @-prefixed Unix epoch timestamps as date strings 2606/head
Zhaofeng Li [Wed, 14 May 2025 22:01:44 +0000 (16:01 -0600)] 
Support @-prefixed Unix epoch timestamps as date strings

Signed-off-by: Zhaofeng Li <hello@zhaofeng.li>
8 weeks agobsdtar: Support `--mtime` and `--clamp-mtime` (#2601)
Zhaofeng Li [Thu, 15 May 2025 12:08:14 +0000 (06:08 -0600)] 
bsdtar: Support `--mtime` and `--clamp-mtime` (#2601)

Hi,

This PR adds support for setting a forced mtime on all written files
(`--mtime` and `--clamp-mtime`) in bsdtar.

The end goal will be to support all functionalities in
<https://reproducible-builds.org/docs/archives/#full-example>, namely
`--sort` and disabling other attributes (atime, ctime, etc.).

Fixes #971.

## History

- [v1](https://github.com/zhaofengli/libarchive/tree/forced-mtime-v1):
Added `archive_read_disk_set_forced_mtime` in libarchive. As a result,
it was only applied when reading from the filesystem and not from other
archives.
- [v2](https://github.com/zhaofengli/libarchive/tree/forced-mtime-v2):
Refactored to apply the forced mtime in `archive_write`.
- v3 (current): Reduced libarchive change to exposing
`archive_parse_date`, moved clamping logic into bsdtar.

---------

Signed-off-by: Zhaofeng Li <hello@zhaofeng.li>
Co-authored-by: Dustin L. Howett <dustin@howett.net>
8 weeks agoAllow setting the original filename for gzip compressed files (#2544)
Marcus Tillmanns [Thu, 15 May 2025 12:07:48 +0000 (14:07 +0200)] 
Allow setting the original filename for gzip compressed files (#2544)

Co-authored-by: Martin Matuška <martin@matuska.de>
8 weeks agocorrect only modes of `--no-mac-metadata` in bsdtar.1 (#2597)
Moroshima [Thu, 15 May 2025 10:59:37 +0000 (18:59 +0800)] 
correct only modes of `--no-mac-metadata` in bsdtar.1 (#2597)

`--no-mac-metadata` is c, r, u and x mode only

8 weeks agoFix mbedtls version 3 compatibility (#2602)
James Hilliard [Thu, 15 May 2025 10:56:59 +0000 (04:56 -0600)] 
Fix mbedtls version 3 compatibility (#2602)

We need to use the new API for mbedtls 3 compatibility

Fixes #2025

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
8 weeks agosafe_printf should annotate with restrict (#2605)
AZero13 [Thu, 15 May 2025 01:24:54 +0000 (21:24 -0400)] 
safe_printf should annotate with restrict (#2605)

printf has restrict for its parameters, and safe_printf should do the
same.

8 weeks ago7z: fix out-of-bounds read in 7z self extracting archive detection 2604/head
Martin Matuska [Wed, 14 May 2025 10:37:26 +0000 (12:37 +0200)] 
7z: fix out-of-bounds read in 7z self extracting archive detection

Fixes OSS-Fuzz issue 416832167

2 months agorar: Fix heap-buffer-overflow (#2599)
Tobias Stoeckmann [Sun, 11 May 2025 17:00:11 +0000 (19:00 +0200)] 
rar: Fix heap-buffer-overflow (#2599)

A filter block size must not be larger than the lzss window, which is
defined
by dictionary size, which in turn can be derived from unpacked file
size.

While at it, improve error messages and fix lzss window wrap around
logic.

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

---------

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Co-authored-by: Tim Kientzle <kientzle@acm.org>
2 months agorar: Fix double free with over 4 billion nodes (#2598)
Tobias Stoeckmann [Sun, 11 May 2025 00:17:19 +0000 (02:17 +0200)] 
rar: Fix double free with over 4 billion nodes (#2598)

If a system is capable of handling 4 billion nodes in memory, a double
free could occur because of an unsigned integer overflow leading to a
realloc call with size argument of 0. Eventually, the client will
release that memory again, triggering a double free.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months ago7z sfx overaly detection (#2088)
mehrabiworkmail [Fri, 9 May 2025 17:21:32 +0000 (10:21 -0700)] 
7z sfx overaly detection (#2088)

To detect 7z SFX files, libarchive currently searches for the 7z header
in a hard-coded addr range of the PE/ELF file
(specified via macros SFX_MIN_ADDR and SFX_MAX_ADDR). This causes it to
miss SFX files that may stray outside these values (libarchive fails to
extract 7z SFX ELF files created by recent versions of 7z tool because
of this issue). This patch fixes the issue by finding a more robust
starting point for the 7z header search: overlay in PE or the .data
section in ELF. This patch also adds 3 new test cases for 7z SFX to
libarchive.

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

---------

Co-authored-by: Masoud Mehrabi Koushki <masoud.mehrabi.koushki1@huawei.com>
Co-authored-by: Martin Matuška <martin@matuska.de>
2 months ago7zip reader: add test for POWERPC filter support for LZMA compressor (#2460)
Mostyn Bramley-Moore [Fri, 9 May 2025 11:40:56 +0000 (13:40 +0200)] 
7zip reader: add test for POWERPC filter support for LZMA compressor (#2460)

This new test archive contains a C hello world executable built like so
on a ubuntu 24.04 machine:
```
int main(int argc, char *argv[]) {
  printf("hello, world\n");
  return 0;
}
```

`powerpc-linux-gnu-gcc hw.c -o hw-powerpc -Wall`

The test archive that contains this executable was created like so,
using 7-Zip 24.08: `7zz a -t7z -m0=lzma2 -mf=ppc
libarchive/test/test_read_format_7zip_lzma2_powerpc.7z hw-powerpc`

The new test archive is required because the powerpc filter for lzma is
implemented in liblzma rather than in libarchive.

2 months agoxar: add xmllite support to the XAR reader and writer (#2388)
Dustin L. Howett [Fri, 9 May 2025 11:40:21 +0000 (06:40 -0500)] 
xar: add xmllite support to the XAR reader and writer (#2388)

This commit adds support for reading and writing XAR archives on Windows
using the built-in xmllite library. xmllite is present in all versions
of Windows starting with Windows XP.

With this change, no external XML library (libxml2, expat) is required
to read or produce XAR archives on Windows.

xmllite is a little bit annoying in that it's entirely a COM API--the
likes of which are annoying to use from C.

Signed-off-by: Dustin L. Howett <dustin@howett.net>
Depends on e619342dfa36b887ffa0ea33e98d04cb161cd7de
Closes #1811

2 months agoPolish for GNU tar format reading/writing (#2455)
Tim Kientzle [Fri, 9 May 2025 11:36:05 +0000 (04:36 -0700)] 
Polish for GNU tar format reading/writing (#2455)

A few small tweaks to improve reading/writing of the legacy GNU tar
format.

* Be more tolerant of redundant 'K' and 'L' headers
* Fill in missing error messages for redundant headers
* New test for reading archive with redundant 'L' headers
* Earlier identification of GNU tar format in some cases

These changes were inspired by Issue #2434. Although that was determined
to not technically be a bug in libarchive, it's relatively easy for
libarchive to tolerate duplicate 'K' and 'L' headers and we should be
issuing appropriate error messages in any case.

2 months agoFix archive_time.c issues (concurrency, 32 bit) (#2563)
Tobias Stoeckmann [Fri, 9 May 2025 11:33:32 +0000 (13:33 +0200)] 
Fix archive_time.c issues (concurrency, 32 bit) (#2563)

The refactoring of https://github.com/libarchive/libarchive/pull/2553
introduced three issues:

1. Introduction of a modifiable global static variable

This violates the goal of having no global variables as stated in [the
README.md](https://github.com/libarchive/libarchive/blob/b6f6557abb8235f604eced6facb42da8c7ab2a41/README.md?plain=1#L195)
which in turn leads to concurrency issues. Without any form of mutex
protection, multiple threads are not guaranteed to see the correct
min/max values. Since these are not needed in regular use cases but only
in edge cases, handle them in functions with local variables only.

Also the global variables are locale-dependent which can change during
runtime. In that case, future calls leads to issues.

2. Broken 32 bit support

The writers for zip and others affected by the previously mentioned PR
and test-suite on Debian 12 i686 are broken, because the calculation of
maximum MS-DOS time is not possible with a 32 bit time_t. Treat these
cases properly.

3. Edge case protection

Huge or tiny int64_t values can easily lead to unsigned integer
overflows. While these do not affect stability of libarchive, the
results are still wrong, i.e. are not capped at min/max as expected.

In total, the functions are much closer to their original versions again
(+ more range checks).

---------

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months agorar: Check packed_size constraints (#2591)
Tobias Stoeckmann [Fri, 9 May 2025 11:31:24 +0000 (13:31 +0200)] 
rar: Check packed_size constraints (#2591)

Make sure that size_t casts do not truncate the value of packed_size on
32 bit systems since it's 64 bit. Extensions to RAR format allow 64 bit
values to be specified in archives.

Also verify that 64 bit signed arithmetics do not overflow.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months agorar: Fix rar_read_ahead call stack overflow (#2592)
Tobias Stoeckmann [Fri, 9 May 2025 11:31:00 +0000 (13:31 +0200)] 
rar: Fix rar_read_ahead call stack overflow (#2592)

It is possible to trigger a call stack overflow by repeatedly entering
the rar_read_ahead function. In normal circumstances, this recursion is
optimized away by common compilers, but default settings with MSVC keep
the recursion in place. Explicitly turn the recursion into a goto-loop
to avoid the overflow even with no compiler optimizations.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months agorar: Clean up br on split archive entries (#2593)
Tobias Stoeckmann [Fri, 9 May 2025 11:30:32 +0000 (13:30 +0200)] 
rar: Clean up br on split archive entries (#2593)

Reset avail_in and next_in if the next entry of a split archive is
parsed to always update its internal structure to access next bytes when
cache runs empty.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months agorar: Support large headers on 32 bit systems (#2596)
Tobias Stoeckmann [Fri, 9 May 2025 11:29:53 +0000 (13:29 +0200)] 
rar: Support large headers on 32 bit systems (#2596)

Support header sizes larger than 32 bit even on 32 bit systems, since
these normally have large file support. Otherwise an unsigned integer
overflow could occur, leading to erroneous parsing on these systems.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months agoUnify spacing in archive_read_support_format_rar.c (#2590)
Tobias Stoeckmann [Sun, 27 Apr 2025 23:22:34 +0000 (01:22 +0200)] 
Unify spacing in archive_read_support_format_rar.c (#2590)

Most source files use tabs instead of spaces, but
archive_read_support_format_rar.c uses spaces most of the time. A few
lines contain a mixture of tabs and spaces, which leads to poorly
formatted output with many default settings.

Unify the style. No functional change and preparation for upcoming
changes to get rid of white space diffs.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months agoImprove support for AFIO 64-bit inode values (#2589)
Tim Kientzle [Sat, 26 Apr 2025 23:10:45 +0000 (16:10 -0700)] 
Improve support for AFIO 64-bit inode values (#2589)

PR #2258 hardened AFIO parsing by converting all inode values >= 2^63 to
zero values. This turns out to be problematic for filesystems that use
very large inode values; it results in all such files being viewed as
hardlinks to each other.

PR #2587 partially addressed this by instead considering inode values >=
2^63 as invalid and just ignoring them. This prevented the accidental
hardlinking, but at the cost of losing all hardlinks that involved large
inode values.

This PR further improves things by stripping the high order bit from
64-bit inode values in the AFIO parser. This allows them to be mostly
preserved and should allow hardlinks to get properly processed in the
vast majority of cases. The only false hardlinks would be when there are
inode values that differ exactly in the high order bit, which should be
very rare.

A full solution will require expanding inode handling to use unsigned
64-bit values; we can't do that without a major version bump, but this
PR also sets the stage for migrating inode support in a future
libarchive 4.0.

2 months agoFix overflow in build_ustar_entry (#2588)
Brian Campbell [Sat, 26 Apr 2025 04:11:19 +0000 (05:11 +0100)] 
Fix overflow in build_ustar_entry (#2588)

The calculations for the suffix and prefix can increment the endpoint
for a trailing slash. Hence the limits used should be one lower than the
maximum number of bytes.

Without this patch, when this happens for both the prefix and the
suffix, we end up with 156 + 100 bytes, and the write of the null at the
end will overflow the 256 byte buffer. This can be reproduced by running
```
mkdir -p foo/bar
bsdtar cvf test.tar foo////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////bar
```
when bsdtar is compiled with Address Sanitiser, although I originally
noticed this by accident with a genuine filename on a CHERI capability
system, which faults immediately on the buffer overflow.

2 months agobsdtar: don't hardlink negative inode files together (#2587)
Dmitry Ivankov [Tue, 22 Apr 2025 14:29:44 +0000 (16:29 +0200)] 
bsdtar: don't hardlink negative inode files together (#2587)

It seems that valid inode can be 64-bit and negative (or rather outside
of 64-bit signed range)

https://github.com/freebsd/freebsd-src/blob/a60615d5be83ca050d4ddfbbb4411ca7a8a11486/sys/sys/_types.h#L124
https://github.com/torvalds/linux/blob/7e74f756f5f643148ca5537bf2fee6767e4b0ed9/include/linux/types.h#L22

But signed type is used in libarchive and there were some fuzzing issues
with it, https://github.com/libarchive/libarchive/pull/2258 converts
negative `ino` to `0`, which is actually a reserved inode value, but
more importantly it was still setting `AE_SET_INO` flag and later on
hardlink detection will treat all `0` on same `dev` as hardlinks to each
other if they have some hardlinks.

This showed up in BuildBarn FUSE filesystem
https://github.com/buildbarn/bb-remote-execution/issues/162 which has
both
- setting number of links to a big value
- generating random inode values in full uint64 range

Which in turn triggers false-positive hardlink detection in `bsdtar`
with high probability.

Let's mitigate it
- don't set `AE_SET_INO` on negative values (assuming rest of code isn't
ready to correctly handle full uint64 range)
- check that `ino + dev` are set in link resolver

2 months agoDo not skip past EOF while reading (#2584)
Tobias Stoeckmann [Tue, 15 Apr 2025 04:02:17 +0000 (06:02 +0200)] 
Do not skip past EOF while reading (#2584)

Make sure to not skip past end of file for better error messages. One
such example is now visible with rar testsuite. You can see the
difference already by an actually not useless use of cat:

```
$ cat .../test_read_format_rar_ppmd_use_after_free.rar | bsdtar -t
bsdtar: Archive entry has empty or unreadable filename ... skipping.
bsdtar: Archive entry has empty or unreadable filename ... skipping.
bsdtar: Truncated input file (needed 119 bytes, only 0 available)
bsdtar: Error exit delayed from previous errors.
```

compared to

```
$ bsdtar -tf .../test_read_format_rar_ppmd_use_after_free.rar
bsdtar: Archive entry has empty or unreadable filename ... skipping.
bsdtar: Archive entry has empty or unreadable filename ... skipping.
bsdtar: Error exit delayed from previous errors.
```

Since the former cannot lseek, the error is a different one
(ARCHIVE_FATAL vs ARCHIVE_EOF). The piped version states explicitly that
truncation occurred, while the latter states EOF because the skip past
the end of file was successful.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months agobsdtar: start "fake short equivalents" enum higher (#2586)
Graham Percival [Mon, 14 Apr 2025 18:39:14 +0000 (11:39 -0700)] 
bsdtar: start "fake short equivalents" enum higher (#2586)

This avoids possible conflict with command-line options such as -B.

2 months agoarchive_version_details: add missing ';' at end of declaration (#2585)
zhongfly [Mon, 14 Apr 2025 14:37:38 +0000 (22:37 +0800)] 
archive_version_details: add missing ';' at end of declaration (#2585)

Close #2579

2 months agotar: Improve LFS support on 32 bit systems (#2582)
Tobias Stoeckmann [Sun, 13 Apr 2025 18:07:18 +0000 (20:07 +0200)] 
tar: Improve LFS support on 32 bit systems (#2582)

The size_t data type is only 32 bit on 32 bit sytems while off_t is
generally 64 bit to support files larger than 2 GB.

If an entry is declared to be larger than 4 GB and the entry shall be
skipped, then 32 bit systems truncate the requested amount of bytes.
This leads to different interpretation of data in tar files compared to
64 bit systems.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months agoAvoid some casts by changing the private API (#2578)
Graham Percival [Sat, 12 Apr 2025 20:58:03 +0000 (13:58 -0700)] 
Avoid some casts by changing the private API (#2578)

3 months agoFix missing newline at EOF (#2577)
Graham Percival [Sat, 12 Apr 2025 03:10:04 +0000 (20:10 -0700)] 
Fix missing newline at EOF (#2577)

3 months agoi should be size_t (#2575)
AZero13 [Fri, 11 Apr 2025 03:14:55 +0000 (23:14 -0400)] 
i should be size_t (#2575)

The size of i does not matter, and a size_t is added to it, so to avoid
that truncation, just make i size_t. It also is passed as a size_t.

3 months agoRemove unnecessary `sharutils` dependency (#2571)
Lukas Javorsky [Wed, 9 Apr 2025 03:23:27 +0000 (05:23 +0200)] 
Remove unnecessary `sharutils` dependency (#2571)

Resolves issue: #2570

3 months agoFixes Windows compile issue (#2538)
ARJANEN Loïc Jean David [Mon, 7 Apr 2025 15:04:27 +0000 (17:04 +0200)] 
Fixes Windows compile issue (#2538)

Solves a Windows compile issue when OpenSSH/mbedTLS/Nettle is activated
and on the build system's paths by making the Windows API backend higher
priority on Windows (meaning that only RIPEMD160 will use
OpenSSH/mbedTLS/Nettle anymore).

Fixes #2536 and starts on #2320.

3 months agowarc: Prevent signed integer overflow (#2568)
Tobias Stoeckmann [Sun, 6 Apr 2025 22:24:13 +0000 (00:24 +0200)] 
warc: Prevent signed integer overflow (#2568)

If a warc archive claims to have more than INT64_MAX - 4 content bytes,
the inevitable failure to skip all these bytes could lead to parsing
data which should be ignored instead.

The test case contains a conversation entry with that many bytes and if
the entry is not properly skipped, the warc implementation would read
the conversation data as a new file entry.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
3 months agoFix #endif comments for header guards (#2567)
Graham Percival [Sun, 6 Apr 2025 21:16:24 +0000 (14:16 -0700)] 
Fix #endif comments for header guards (#2567)