]> git.ipfire.org Git - thirdparty/libarchive.git/log
thirdparty/libarchive.git
7 weeks agoMerge pull request #2940 from wrp/wrp/doc
Tim Kientzle [Fri, 20 Mar 2026 15:43:08 +0000 (08:43 -0700)] 
Merge pull request #2940 from wrp/wrp/doc

Provide more details on autotool meta-files

7 weeks agoProvide more details on autotool meta-files 2940/head
William Pursell [Fri, 20 Mar 2026 15:03:59 +0000 (09:03 -0600)] 
Provide more details on autotool meta-files

Given the amount of confusion surrounding the autotools, it is
better to have accurate descriptions of these files in the
README.

7 weeks agocpio: Fix -R memory leak 2939/head
Tobias Stoeckmann [Fri, 20 Mar 2026 12:40:19 +0000 (13:40 +0100)] 
cpio: Fix -R memory leak

If the -R command line argument is supplied with user/group names
multiple times, memory leaks occur.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agopathmatch: Anchors within pattern not special 2924/head
Tobias Stoeckmann [Wed, 18 Mar 2026 10:17:02 +0000 (11:17 +0100)] 
pathmatch: Anchors within pattern not special

The anchor characters ^ and $ have only special meanings if they are
located at the beginning (^) or at the end ($) of the pattern. And even
then they are supposed to be only special if flags are set.

If they are located within the pattern itself, they are regular
characters regardless of flags.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agozip: Unify error code formatting in error messages 2922/head
Tobias Stoeckmann [Wed, 18 Mar 2026 08:20:01 +0000 (09:20 +0100)] 
zip: Unify error code formatting in error messages

This unifies the way error codes are shown in error messages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agorar5: Remove "Error: " prefix from error message
Tobias Stoeckmann [Wed, 18 Mar 2026 08:19:15 +0000 (09:19 +0100)] 
rar5: Remove "Error: " prefix from error message

Unifies style with other error messages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agoFix whitespace style in error messages
Tobias Stoeckmann [Wed, 18 Mar 2026 08:15:53 +0000 (09:15 +0100)] 
Fix whitespace style in error messages

- Keep a whitespace between text and brackets
- No whitespace between text and colon
- No newline at end of error message

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks ago7zip: Fix typo in error message
Tobias Stoeckmann [Wed, 18 Mar 2026 08:14:25 +0000 (09:14 +0100)] 
7zip: Fix typo in error message

Failed should be written without capital letter here.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agoRemove periods from error messages
Tobias Stoeckmann [Wed, 18 Mar 2026 08:12:51 +0000 (09:12 +0100)] 
Remove periods from error messages

Some error messages previously slipped through. Remove periods from
these messages as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agoMerge pull request #2921 from stoeckmann/err_style_regression
Tim Kientzle [Wed, 18 Mar 2026 12:58:45 +0000 (05:58 -0700)] 
Merge pull request #2921 from stoeckmann/err_style_regression

Fix Windows test regression

8 weeks agoFix Windows test regression 2921/head
Tobias Stoeckmann [Wed, 18 Mar 2026 08:03:00 +0000 (09:03 +0100)] 
Fix Windows test regression

By only removing periods from error messages in Windows specific code,
but not adjusting its POSIX counterpart, the test fails on Windows but
not on POSIX systems.

Fix this by removing the period in test and in POSIX error messages.

Fixes: 3e0819b59e ("libarchive: Remove period from error messages")
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agoMerge pull request #2912 from stoeckmann/pax_ugid
Tim Kientzle [Wed, 18 Mar 2026 03:11:29 +0000 (20:11 -0700)] 
Merge pull request #2912 from stoeckmann/pax_ugid

pax: Remove uid/gid cast in value range check

8 weeks agoMerge pull request #2913 from stoeckmann/cpio_buff
Tim Kientzle [Wed, 18 Mar 2026 03:09:54 +0000 (20:09 -0700)] 
Merge pull request #2913 from stoeckmann/cpio_buff

cpio: Reduce visibility of variable buff

8 weeks agoMerge pull request #2915 from stoeckmann/err_style
Tim Kientzle [Wed, 18 Mar 2026 03:07:55 +0000 (20:07 -0700)] 
Merge pull request #2915 from stoeckmann/err_style

libarchive: Improve error message style

8 weeks agoFix Heap OOB Write in CAB LZX decoder
LoboQ1ng [Wed, 18 Mar 2026 00:24:40 +0000 (00:24 +0000)] 
Fix Heap OOB Write in CAB LZX decoder

8 weeks agolibarchive: Fix error message style 2915/head
Tobias Stoeckmann [Tue, 17 Mar 2026 09:47:52 +0000 (10:47 +0100)] 
libarchive: Fix error message style

Remove space in front of colon to match rest of messages.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agolibarchive: Remove "Failed : " error prefixes
Tobias Stoeckmann [Tue, 17 Mar 2026 09:46:25 +0000 (10:46 +0100)] 
libarchive: Remove "Failed : " error prefixes

Calling archive_set_error with a message and errno already indicates
that a failure occurred. Only a minority of functions did that: Unify
with the rest.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agolibarchive: Remove period from error messages
Tobias Stoeckmann [Tue, 17 Mar 2026 09:41:25 +0000 (10:41 +0100)] 
libarchive: Remove period from error messages

The error messages are mostly written without a period. This makes
sense, because they can be accompanied with a strerror(errno) call,
giving more information: most likely a colon is appended.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agocpio: Reduce visibility of variable buff 2913/head
Tobias Stoeckmann [Tue, 17 Mar 2026 09:08:42 +0000 (10:08 +0100)] 
cpio: Reduce visibility of variable buff

The buff variable is only used in entry_to_archive. Moving it into the
specific code block where it is actually used reduces its visibility and
thus makes it easier to read the code:

Since Windows indeed uses unsigned for read, this makes it much easier
to verify that buff never grows and cannot be too large.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agopax: Remove uid/gid cast in value range check 2912/head
Tobias Stoeckmann [Tue, 17 Mar 2026 08:35:55 +0000 (09:35 +0100)] 
pax: Remove uid/gid cast in value range check

The API allows to set int64_t uid/gid values. When writing pax archives,
such large values are properly set in the USTAR header of actual data in
base256, i.e. everything works.

The pax header entries might be missing though because the check
truncates these values to unsigned int. Larger values could be truncated
in a way that they seem smaller than (1 << 18).

The check in line 1427 which sets the uid/gid values into the PAX header
block is correct, truncating the actual value to max. octal
representation.

This is a purely defensive change to support parsers which actually
allow such large uid/gid values but do not understand base256 encoding.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agoMerge pull request #2911 from stoeckmann/libarchive_opt_vals
Tim Kientzle [Mon, 16 Mar 2026 21:01:33 +0000 (14:01 -0700)] 
Merge pull request #2911 from stoeckmann/libarchive_opt_vals

libarchive: Check number ranges of supplied option values

8 weeks agolibarchive/{b64,uu}: Improve atol8 checks 2911/head
Tobias Stoeckmann [Mon, 16 Mar 2026 15:00:30 +0000 (16:00 +0100)] 
libarchive/{b64,uu}: Improve atol8 checks

Make sure that supplied values cannot overflow int64_t, which would be
an undefined behavior. Also do not accept empty strings as numbers.

Last but not least, check values before casting them to target data
types to avoid truncations.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agolibarchive: Check strto(u)l results before casts
Tobias Stoeckmann [Mon, 16 Mar 2026 14:59:12 +0000 (15:59 +0100)] 
libarchive: Check strto(u)l results before casts

Make sure that supplied option values fit into data types. If not,
return an error instead of silently truncating values.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agolibarchive/7zip: Properly check strto* errno value
Tobias Stoeckmann [Mon, 16 Mar 2026 14:57:17 +0000 (15:57 +0100)] 
libarchive/7zip: Properly check strto* errno value

Set errno to 0 before calling strtoimax/strtol and check its value
afterwards.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agolibarchive/gzip: Check strdup return value
Tobias Stoeckmann [Mon, 16 Mar 2026 14:54:16 +0000 (15:54 +0100)] 
libarchive/gzip: Check strdup return value

Handle strdup error instead of silently ignoring the option.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agoMerge pull request #2910 from stoeckmann/cpio_num
Tim Kientzle [Mon, 16 Mar 2026 13:56:31 +0000 (06:56 -0700)] 
Merge pull request #2910 from stoeckmann/cpio_num

cpio: Check number arguments before casts

8 weeks agoMerge pull request #2909 from stoeckmann/lafe_error
Tim Kientzle [Mon, 16 Mar 2026 13:47:14 +0000 (06:47 -0700)] 
Merge pull request #2909 from stoeckmann/lafe_error

tools: Remove `Error : ` prefix in lafe_errc calls

8 weeks agoMerge pull request #2908 from stoeckmann/cpio_mode
Tim Kientzle [Mon, 16 Mar 2026 13:46:38 +0000 (06:46 -0700)] 
Merge pull request #2908 from stoeckmann/cpio_mode

cpio: Improve mode option handling

8 weeks agocpio: Set lafe_warnc code to 0 2910/head
Tobias Stoeckmann [Mon, 16 Mar 2026 13:34:32 +0000 (14:34 +0100)] 
cpio: Set lafe_warnc code to 0

Otherwise an unknown error is printed, which does not help the user
(especially since a custom message is printed in this case already).

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agoMerge pull request #2872 from stoeckmann/filter_options_failed
Tim Kientzle [Mon, 16 Mar 2026 13:30:07 +0000 (06:30 -0700)] 
Merge pull request #2872 from stoeckmann/filter_options_failed

filter options: Use ARCHIVE_FAILED on errors

8 weeks agoMerge pull request #2899 from stoeckmann/cpio_rename
Tim Kientzle [Mon, 16 Mar 2026 13:28:55 +0000 (06:28 -0700)] 
Merge pull request #2899 from stoeckmann/cpio_rename

cpio: Allow long paths with -r option

8 weeks agocpio: Check number arguments before casts
Tobias Stoeckmann [Mon, 16 Mar 2026 13:10:50 +0000 (14:10 +0100)] 
cpio: Check number arguments before casts

Make sure that supplied arguments actually fit into target data types.
Print an error if numbers are too large instead of silently truncating
them.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agotools: Remove 'Error : ' prefix in lafe_errc calls 2909/head
Tobias Stoeckmann [Mon, 16 Mar 2026 13:01:56 +0000 (14:01 +0100)] 
tools: Remove 'Error : ' prefix in lafe_errc calls

Only a minority of calls to lafe_errc state explicitly that an error
occurred. Remove these few cases for a more unified argument handling.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agocpio: Clarify that onyl one mode is acceptable 2908/head
Tobias Stoeckmann [Mon, 16 Mar 2026 12:50:42 +0000 (13:50 +0100)] 
cpio: Clarify that onyl one mode is acceptable

Do not print that at least one mode has to be supplied. Exactly one mode
has to be supplied instead.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agocpio: Improve mode argument checks
Tobias Stoeckmann [Mon, 16 Mar 2026 09:16:19 +0000 (10:16 +0100)] 
cpio: Improve mode argument checks

Complain only if contradicting mode options are supplied. Passing the
same argument multiple times should not lead to errors.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agofilter options: Use ARCHIVE_FAILED on errors 2872/head
Tobias Stoeckmann [Sun, 22 Feb 2026 14:49:27 +0000 (15:49 +0100)] 
filter options: Use ARCHIVE_FAILED on errors

If a filter option is recognized but its value is invalid, return
ARCHIVE_FAILED instead of ARCHIVE_WARN. The latter is used for unknown
options, e.g. at the end of the option setter functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
8 weeks agocpio: Use getline in cpio_rename 2899/head
Tobias Stoeckmann [Mon, 9 Mar 2026 20:40:09 +0000 (21:40 +0100)] 
cpio: Use getline in cpio_rename

The buffer has a fixed 1024 limit, which can be smaller than the maximum
allowed path length. Increasing the limit to 4096 would partially help,
but since leading spaces are stripped, input lines could be valid and
longer.

Use getline instead.

8 weeks agocpio: Refactor cpio_rename
Tobias Stoeckmann [Mon, 9 Mar 2026 20:35:09 +0000 (21:35 +0100)] 
cpio: Refactor cpio_rename

Let cpio_rename work with the entry directly. In this initial step, it
moves buff into the stack.

The comment suggests that this was done in the past already.

8 weeks agoMove la_getline into libarchive_fe
Tobias Stoeckmann [Mon, 9 Mar 2026 20:28:00 +0000 (21:28 +0100)] 
Move la_getline into libarchive_fe

This allows easier reuse of the getline implementation in other tools
like cpio (in upcoming commit).

8 weeks agoAdd missing HAVE_STDIO_H cmake check
Tobias Stoeckmann [Mon, 9 Mar 2026 20:00:14 +0000 (21:00 +0100)] 
Add missing HAVE_STDIO_H cmake check

The check is performed by configure, but not with cmake. The
bsdunzip/la_getline.c file checks for presence of this definition.

8 weeks agoMerge pull request #2871 from stoeckmann/archive_options_either
Tim Kientzle [Mon, 16 Mar 2026 02:21:37 +0000 (19:21 -0700)] 
Merge pull request #2871 from stoeckmann/archive_options_either

libarchive: Correctly handle option failures

8 weeks agoMerge pull request #2900 from LoboQ1ng/fix-cab-null-deref
Tim Kientzle [Mon, 16 Mar 2026 01:41:04 +0000 (18:41 -0700)] 
Merge pull request #2900 from LoboQ1ng/fix-cab-null-deref

Fix NULL pointer dereference in CAB parser during skip

8 weeks agoMerge pull request #2903 from ZUENS2020/codex/fix-untar-parseoct-bounds-check
Tim Kientzle [Mon, 16 Mar 2026 01:39:32 +0000 (18:39 -0700)] 
Merge pull request #2903 from ZUENS2020/codex/fix-untar-parseoct-bounds-check

Fix OOB read in contrib/untar.c parseoct()

8 weeks agoMerge pull request #2901 from stoeckmann/cpio_llp64
Tim Kientzle [Mon, 16 Mar 2026 01:39:10 +0000 (18:39 -0700)] 
Merge pull request #2901 from stoeckmann/cpio_llp64

tools: Cast int64_t to long long in printf

2 months agoFix NULL pointer dereference in archive_acl_from_text_nl 2905/head
Georgios Patsakas [Thu, 12 Mar 2026 20:24:13 +0000 (22:24 +0200)] 
Fix NULL pointer dereference in archive_acl_from_text_nl

### Summary
This PR fixes a NULL pointer dereference in `archive_acl_from_text_nl()` (located in `archive_acl.c`) that occurs when parsing malformed PAX tar archives containing a short "default" ACL prefix.

### Technical Details
This is a variant of the bug previously fixed in the wide-character version `archive_acl_from_text_w()` via commit 7a6549a6 (Issue #2744).

The vulnerability exists because `st = field[n].start + 1` is calculated before verifying if the field length is zero. In cases of malformed entries, `field[n].start` can be NULL, leading to Undefined Behavior/SIGILL. This patch applies the same logic from the wide-char fix: moving the pointer increment after the length guard.

### Validation
- **Environment:** Ubuntu 24.04, compiled with AddressSanitizer (ASan) and UndefinedBehaviorSanitizer (UBSan).
- **Reproduction:** Verified that the minimized PAX tar archive provided in issue #2904 no longer triggers the crash.
- **Regression:** All existing library tests pass.

Closes #2904

2 months agoFix OOB read in contrib/untar.c parseoct() 2903/head
ZUENS2020 [Wed, 11 Mar 2026 13:34:58 +0000 (21:34 +0800)] 
Fix OOB read in contrib/untar.c parseoct()

Reported-by: ZUENS2020
2 months agotar: print int64_t uid/gid as long long 2901/head
Tobias Stoeckmann [Tue, 10 Mar 2026 19:10:24 +0000 (20:10 +0100)] 
tar: print int64_t uid/gid as long long

On LLP64 systems like Windows 11, overly large uid/gid values would be
truncated.

Same is true on Linux 32 bit.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months agocpio: Cast int64_t to long long in printf
Tobias Stoeckmann [Tue, 10 Mar 2026 17:20:40 +0000 (18:20 +0100)] 
cpio: Cast int64_t to long long in printf

LLP64 systems like Windows 11 have a 32 bit long. Cast int64_t to
long long for better output.

Same is true for 32 bit systems.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months agoFix NULL pointer dereference in CAB parser during skip 2900/head
LoboQ1ng [Tue, 10 Mar 2026 17:04:43 +0000 (17:04 +0000)] 
Fix NULL pointer dereference in CAB parser during skip

When parsing a malformed CAB file, the skip routine (cab_checksum_finish) blindly calculated the checksum on an uninitialized cfdata->memimage. This patch adds a NULL check before the checksum calculation and includes a standalone test case with a minimized malformed payload to prevent regressions.

2 months agoMerge pull request #2877 from kientzle/kientzle-rar5-loop-bug
Tim Kientzle [Tue, 10 Mar 2026 02:52:31 +0000 (19:52 -0700)] 
Merge pull request #2877 from kientzle/kientzle-rar5-loop-bug

Infinite loop in Rar5 decompression

2 months agoReject filters when the block length is nonsensical 2877/head
Tim Kientzle [Mon, 2 Mar 2026 04:24:56 +0000 (20:24 -0800)] 
Reject filters when the block length is nonsensical

Credit: Grzegorz Antoniak @antekone

2 months agoInfinite loop in Rar5 decompression
Tim Kientzle [Sun, 1 Mar 2026 18:04:01 +0000 (10:04 -0800)] 
Infinite loop in Rar5 decompression

Found by: Elhanan Haenel

2 months agoAdd TODO comment for future error propagation 2897/head
elhananhaenel [Sun, 8 Mar 2026 13:33:50 +0000 (15:33 +0200)] 
Add TODO comment for future error propagation

2 months agoFix -Wsign-compare: cast mask+1 to unsigned int 2898/head
elhananhaenel [Sun, 8 Mar 2026 13:29:46 +0000 (15:29 +0200)] 
Fix -Wsign-compare: cast mask+1 to unsigned int

2 months agorar: fix LZSS window size mismatch after PPMd block
elhananhaenel [Sat, 7 Mar 2026 20:32:09 +0000 (22:32 +0200)] 
rar: fix LZSS window size mismatch after PPMd block

When a PPMd-compressed block updates dictionary_size, the LZSS window
from a prior block is not reallocated. The allocation guard only checks
if dictionary_size is zero or the window pointer is NULL, not whether
the existing window is large enough. This allows copy_from_lzss_window()
to read past the allocated buffer.

Fix the guard to also check whether the current window is undersized.
Add bounds checks in copy_from_lzss_window() and parse_filter() as
defense in depth.

2 months agoiso9660: validate pz_log2_bs in parse_rockridge_ZF1()
elhananhaenel [Sat, 7 Mar 2026 20:14:23 +0000 (22:14 +0200)] 
iso9660: validate pz_log2_bs in parse_rockridge_ZF1()

The zisofs block size exponent (pz_log2_bs) read from the Rock Ridge ZF
extension entry is used directly in shift expressions without validation.
The zisofs specification only permits values 15, 16, or 17 (corresponding
to 32K, 64K, and 128K block sizes).

When pz_log2_bs >= 64 on 64-bit systems (or >= 32 on 32-bit), the
expression (size_t)1UL << pz_log2_bs is undefined behavior per C11
6.5.7. On 32-bit systems, a large exponent also causes the block pointer
allocation size computation (ceil + 1) * 4 to overflow to zero, leading
to a heap buffer overflow write after malloc(0).

Fix: reject any pz_log2_bs outside the range [15, 17] by disabling
zisofs for the entry (file->pz = 0), which prevents the zisofs
decompression path from executing.

Found by fuzzing with ASAN/UBSAN.

2 months agoMerge pull request #2896 from kientzle/kientzle-fix-omitted-uu
Tim Kientzle [Sat, 7 Mar 2026 18:53:05 +0000 (10:53 -0800)] 
Merge pull request #2896 from kientzle/kientzle-fix-omitted-uu

Add UU file from #2864 to Makefile.am

2 months agoAdd UU file from #2864 to Makefile.am 2896/head
Tim Kientzle [Sat, 7 Mar 2026 18:46:43 +0000 (10:46 -0800)] 
Add UU file from #2864 to Makefile.am

2 months agoMerge pull request #2889 from OwenSanzas/fix/linkify-fuzzer-double-free
Tim Kientzle [Sat, 7 Mar 2026 18:29:36 +0000 (10:29 -0800)] 
Merge pull request #2889 from OwenSanzas/fix/linkify-fuzzer-double-free

Fix double-free in libarchive_linkify_fuzzer

2 months agoMerge pull request #2864 from vdsilva/patch
Tim Kientzle [Sat, 7 Mar 2026 18:15:44 +0000 (10:15 -0800)] 
Merge pull request #2864 from vdsilva/patch

7zip: Fix SEGV in check_7zip_header_in_sfx via ELF offset validation

2 months agoMerge pull request #2892 from antekone/feature/8192-filters-memleak/1
Tim Kientzle [Sat, 7 Mar 2026 18:09:26 +0000 (10:09 -0800)] 
Merge pull request #2892 from antekone/feature/8192-filters-memleak/1

RAR5 reader: fix potential memory leak

2 months agoMerge pull request #2893 from antekone/feature/github/1963/init-twice/1
Tim Kientzle [Sat, 7 Mar 2026 18:08:49 +0000 (10:08 -0800)] 
Merge pull request #2893 from antekone/feature/github/1963/init-twice/1

RAR5 reader: fix SIGSEGV when archive_read_support_format_rar5 is called twice

2 months agoMerge pull request #2895 from antekone/feature/github-1980/memleak-in-cab/1
Tim Kientzle [Sat, 7 Mar 2026 18:07:49 +0000 (10:07 -0800)] 
Merge pull request #2895 from antekone/feature/github-1980/memleak-in-cab/1

CAB reader: fix memory leak on repeated calls to archive_read_support_format_cab

2 months agoCAB reader: fix memory leak on repeated calls to archive_read_support_format_cab 2895/head
Grzegorz Antoniak [Sat, 7 Mar 2026 10:30:06 +0000 (11:30 +0100)] 
CAB reader: fix memory leak on repeated calls to archive_read_support_format_cab

`archive_read_support_format_cab` allocates a fresh context structure on
each call before registering the CAB format with libarchive. On the
second call, however, the registration step reports the format is
already registered, so the function frees the newly allocated context
structure — it is not needed, since the one from the first call is
already in use.

The context structure contains a `ws` field of type `archive_wstring`.
During initialization, `archive_wstring_ensure` is called on that field,
which performs its own heap allocation.

The cleanup path described above frees the context structure without
also releasing the memory owned by the `ws` field, causing a leak.

Fixed by calling `archive_wstring_free` on the `ws` field before freeing
the context structure.

Fixes #1980.

2 months agoMerge pull request #2888 from seb128/archive-read-valgrind
Tim Kientzle [Sat, 7 Mar 2026 01:33:15 +0000 (17:33 -0800)] 
Merge pull request #2888 from seb128/archive-read-valgrind

archive_read: optimize string copy, avoid redundant strlen

2 months agoRAR5 reader: fix SIGSEGV when archive_read_support_format_rar5 is called twice 2893/head
Grzegorz Antoniak [Fri, 6 Mar 2026 18:52:22 +0000 (19:52 +0100)] 
RAR5 reader: fix SIGSEGV when archive_read_support_format_rar5 is called twice

When the same archive_read object registers rar5 format more than once,
__archive_read_register_format returns ARCHIVE_WARN (duplicate bid).
The error path then called rar5_cleanup(ar), which dereferences
a->format to get the rar5 context — but a->format is NULL until
archive_read_open() is called, causing a SIGSEGV. The newly allocated
rar struct was also leaked.

Fix by introducing rar5_deinit() (the inverse of rar5_init) and using
it in both rar5_cleanup() and the registration error path. On failure,
the locally allocated rar is freed directly without going through
a->format. The function now always returns ARCHIVE_OK, consistent with
all other format handlers.

Fixes #1963.

2 months agoRAR5 reader: fix potential memory leak 2892/head
Grzegorz Antoniak [Fri, 6 Mar 2026 18:03:38 +0000 (19:03 +0100)] 
RAR5 reader: fix potential memory leak

If a file declares more than 8192 filters at once, without consuming
them, then the filter allocation function leaks memory.

The backing array used for storing filter pointers can hold up to 8192
pointers. After that it won't accept any new entries. The problem was
that the caller code didn't check if the backing array has accepted the
pointer; it silently assumed the pointer was registered, disposing the
only variable that was holding the pointer to allocated memory.

The fix is to fail the creation of a new filter structure if the backing
array is full. This will result in failure to unpack, but having more
than 8192 filters in one file at the same time seems unlikely.

Fixes issue #2891

2 months agoFix double-free in libarchive_linkify_fuzzer 2889/head
OwenSanzas [Thu, 5 Mar 2026 19:03:46 +0000 (19:03 +0000)] 
Fix double-free in libarchive_linkify_fuzzer

The fuzzer fails to update entries[i] after archive_entry_linkify()
modifies the pointer (caching or swapping entries). This causes the
cleanup loop to free entries that were already freed via spare or
the drain loop, resulting in heap-use-after-free.

Fix: add entries[i] = entry after the linkify call to track ownership.

2 months agoarchive_read: optimize string copy, avoid redundant strlen 2888/head
Sebastien Bacher [Thu, 5 Mar 2026 12:24:30 +0000 (13:24 +0100)] 
archive_read: optimize string copy, avoid redundant strlen

Calculate the filename length only once during read_file_data
initialization and replace strcpy with memcpy.

As a side effect it also helps silencing valgrind warnings due to strcpy
word-based optimization
https://github.com/libarchive/libarchive/issues/2887

2 months agoMerge pull request #2885 from kpatsakis/signature-malloc-null-check
Tim Kientzle [Wed, 4 Mar 2026 04:38:33 +0000 (20:38 -0800)] 
Merge pull request #2885 from kpatsakis/signature-malloc-null-check

Unchecked malloc result in archive_read_support_filter_program_signature()

2 months agoIf malloc() returns NULL (e.g., under memory pressure, container memory limits, or... 2885/head
Constantinos Patsakis [Mon, 2 Mar 2026 19:40:53 +0000 (21:40 +0200)] 
If malloc() returns NULL (e.g., under memory pressure, container memory limits, or constrained embedded environments), the subsequent memcpy(NULL, ...) produces a SIGSEGV.

2 months agoMerge pull request #2855 from dag-erling/des/mkdir-errno
Tim Kientzle [Mon, 2 Mar 2026 18:17:48 +0000 (10:17 -0800)] 
Merge pull request #2855 from dag-erling/des/mkdir-errno

archive_write_disk_posix: Report correct error

2 months agoUnbreak CMake build 2855/head
Dag-Erling Smørgrav [Mon, 2 Mar 2026 17:18:32 +0000 (18:18 +0100)] 
Unbreak CMake build

2 months agoMerge pull request #2856 from bradking/pathname-encoding
Tim Kientzle [Mon, 2 Mar 2026 15:20:23 +0000 (07:20 -0800)] 
Merge pull request #2856 from bradking/pathname-encoding

archive_write: Fix crash on failure to convert WCS/UTF-8 pathname to MBS

2 months agotest_main: Run tests as unprivileged user
Dag-Erling Smørgrav [Mon, 2 Mar 2026 10:47:12 +0000 (11:47 +0100)] 
test_main: Run tests as unprivileged user

If run as root (as is the case in CI), switch to an unprivileged user
(default: nobody) before running each test, and switch back after.
This makes it possible to write tests that rely on file permissions.

Note that tests that use the UID or GID must now check the EUID / EGID
instead as they will be different while the test is running.  The only
way to avoid that is to run each test case in a child process, which
would hugely increase the complexity of test_run().

2 months agotest_main: Add assertChown
Dag-Erling Smørgrav [Mon, 2 Mar 2026 10:42:01 +0000 (11:42 +0100)] 
test_main: Add assertChown

2 months agoAdd test case for failing to create directory
Dag-Erling Smørgrav [Fri, 6 Feb 2026 10:14:08 +0000 (11:14 +0100)] 
Add test case for failing to create directory

2 months agoarchive_write_disk_posix: Report correct error
Dag-Erling Smørgrav [Fri, 6 Feb 2026 00:54:50 +0000 (01:54 +0100)] 
archive_write_disk_posix: Report correct error

When create_dir() fails to create a directory, it immediately checks to
see if the directory already exists, which can happen if it's been given
something like foo/../foo.  Unfortunately, this clobbers errno, which
means that create_dir() always reports ENOENT, regardless of the actual
error.  Fix this by only performing this extra check if errno is EEXIST,
then reset errno to either EEXIST or ENOTDIR depending on the outcome.

2 months agoMerge pull request #2880 from kientzle/kientzle-lha-oversize-header
Tim Kientzle [Sun, 1 Mar 2026 23:27:25 +0000 (15:27 -0800)] 
Merge pull request #2880 from kientzle/kientzle-lha-oversize-header

Reject LHA archives with ridiculously large headers

2 months agoRemove unused var 2880/head
Tim Kientzle [Sun, 1 Mar 2026 21:52:57 +0000 (13:52 -0800)] 
Remove unused var

2 months agoReject LHA archives with ridiculously large headers
Tim Kientzle [Sun, 1 Mar 2026 21:45:50 +0000 (13:45 -0800)] 
Reject LHA archives with ridiculously large headers

The header is a series of blocks, most of which contain
values of just a few bytes (sizes, times, etc).  The only
exceptions are the filename and directory name attributes,
which will be limited by the MSDOS/Windows maximum file length
limit.  So it seems unlikely that this will ever exceed 64k.
(If we find counter-examples, we can easily extend this limit.)

2 months agoMerge pull request #2878 from LoboQ1ng/fix-mtree-fd-leak
Tim Kientzle [Sun, 1 Mar 2026 20:46:39 +0000 (12:46 -0800)] 
Merge pull request #2878 from LoboQ1ng/fix-mtree-fd-leak

Fix file descriptor leak in mtree parser cleanup (CWE-775)

2 months agoMerge pull request #2879 from kientzle/kientzle-prune-freebsd-ci
Tim Kientzle [Sun, 1 Mar 2026 20:45:55 +0000 (12:45 -0800)] 
Merge pull request #2879 from kientzle/kientzle-prune-freebsd-ci

Prune FreeBSD CI from 10 variations down to 3

2 months agoNon-snap images are RELEASE, not STABLE 2879/head
Tim Kientzle [Sun, 1 Mar 2026 20:31:48 +0000 (12:31 -0800)] 
Non-snap images are RELEASE, not STABLE

2 months agoDon't use snap image here
Tim Kientzle [Sun, 1 Mar 2026 20:30:09 +0000 (12:30 -0800)] 
Don't use snap image here

2 months agoPrune FreeBSD CI from 10 variations down to 3
Tim Kientzle [Sun, 1 Mar 2026 20:17:05 +0000 (12:17 -0800)] 
Prune FreeBSD CI from 10 variations down to 3

Previously, we tested many combinations of FreeBSD version, build system, and filesystem.
In practice, that's redundant, and we've started seeing these excessive requests get throttled by Cirrus.
Cutting back to just 3 combinations should suffice and reduce the risk of throttling.

2 months agomtree: fix file descriptor leak in cleanup 2878/head
LoboQ1ng [Sun, 1 Mar 2026 19:53:47 +0000 (19:53 +0000)] 
mtree: fix file descriptor leak in cleanup

Close any dangling file descriptor in the mtree cleanup function to prevent FD exhaustion (CWE-775) when a read loop is aborted early.

2 months agoMerge pull request #2875 from bradking/7z-elf64
Tim Kientzle [Sat, 28 Feb 2026 04:15:39 +0000 (20:15 -0800)] 
Merge pull request #2875 from bradking/7z-elf64

7zip: Fix out-of-bounds access on ELF 64-bit header

2 months ago7zip: Fix out-of-bounds access on ELF 64-bit header 2875/head
Brad King [Fri, 27 Feb 2026 19:35:55 +0000 (14:35 -0500)] 
7zip: Fix out-of-bounds access on ELF 64-bit header

The ELF specification's `Elf64_Ehdr` type is 64 bytes [1].
`find_elf_data_sec` accesses the last field, `e_shstrndx`.
Make sure we read enough data to populate it.

[1] https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html

2 months agolibarchive: Correctly handle option failures 2871/head
Tobias Stoeckmann [Sun, 22 Feb 2026 13:42:39 +0000 (14:42 +0100)] 
libarchive: Correctly handle option failures

If an incorrect option value has been passed to a filter, it is possible
that library operations continue without even printing a warning.

This can happen because the special value "ARCHIVE_WARN - 1" is only
checked for filter issues, not format issues. Since this special value
is larger than ARCHIVE_FAILED, such failures are silently discarded.

Fix this by checking for this magic value for formats as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2 months ago7zip: Fix SEGV in check_7zip_header_in_sfx via ELF offset validation 2864/head
Vijay D'Silva [Thu, 12 Feb 2026 03:51:51 +0000 (03:51 +0000)] 
7zip: Fix SEGV in check_7zip_header_in_sfx via ELF offset validation

The crash reported in this issue is caused by a segmentation fault
that happens when a pointer `p` passed to `check_7zip_header_in_sfx`
is dereferenced. That argument `p` is defined as `p = buff + offset` in
`archive_read_format_7zip_bid` with `offset` determined by a call
to `find_elf_data_sec`.

Within `find_elf_data_sec`, a 64-bit ELF section offset is cast
to `ssize_t`. For a sufficiently large offset, such as an unsigned
64-bit value exceeding `SSIZE_MAX`, the `ssize_t` will be negative,
which leads to `p` to point before the start of the buffer.

This patch eliminates the problem by:
1. Reading the ELF section offset into a `uint64_t`.
2. Validating that the offset does not exceed `SSIZE_MAX`.
3. If the offset is invalid, breaking the loop to retain the safe
   default `SFX_MIN_ADDR`.

These checks ensure that `min_addr` is always within the bounds of the buffer.
This PR includes a regression test `test_malformed3` in
`test_read_format_7zip_malformed.c` using a crafted reproducer file.

CodeMender verified with AddressSanitizer that the crash is resolved and the
test suite passes.

Co-authored-by: CodeMender <codemender-patching@google.com>
Fixes: https://issues.oss-fuzz.com/issues/470963352
3 months agoMerge pull request #2858 from FooIbar/nettle-4.x
Tim Kientzle [Wed, 11 Feb 2026 04:00:27 +0000 (20:00 -0800)] 
Merge pull request #2858 from FooIbar/nettle-4.x

Fix incompatibility with Nettle 4.x

3 months agoMerge pull request #2860 from xTibor/fix-iso-year
Tim Kientzle [Wed, 11 Feb 2026 03:43:31 +0000 (19:43 -0800)] 
Merge pull request #2860 from xTibor/fix-iso-year

bsdunzip: Fix ISO week year and Gregorian year confusion

3 months agoMerge pull request #2859 from zhangjy1014/fix-issue-2744
Tim Kientzle [Mon, 9 Feb 2026 15:20:41 +0000 (07:20 -0800)] 
Merge pull request #2859 from zhangjy1014/fix-issue-2744

Fix NULL pointer dereference in archive_acl_from_text_w()

3 months agobsdunzip: Fix ISO week year and Gregorian year confusion 2860/head
Nagy Tibor [Mon, 9 Feb 2026 05:39:22 +0000 (06:39 +0100)] 
bsdunzip: Fix ISO week year and Gregorian year confusion

3 months agoAdd test for malformed "default" ACL prefix (issue #2744) 2859/head
zhangjy1014 [Mon, 9 Feb 2026 03:20:18 +0000 (11:20 +0800)] 
Add test for malformed "default" ACL prefix (issue #2744)

Verify that archive_entry_acl_from_text() and
archive_entry_acl_from_text_w() return ARCHIVE_WARN instead of
crashing when given a bare "d" or "default" string with no
subsequent tag field.

Without the accompanying fix in archive_acl.c this test triggers
a NULL-pointer dereference (SEGV) in archive_acl_from_text_w().

3 months agoFix NULL pointer dereference in archive_acl_from_text_w()
zhangjy1014 [Sun, 8 Feb 2026 09:18:43 +0000 (17:18 +0800)] 
Fix NULL pointer dereference in archive_acl_from_text_w()

When parsing a short "default" ACL prefix (e.g. L"d") with no
subsequent tag field, field[n] is left as {NULL, NULL} and the
code dereferences it unconditionally in the switch statement,
causing a SEGV.

Add a zero-length check after computing the field length so that
malformed entries are skipped with ARCHIVE_WARN, matching the
documented contract. Also move the st pointer computation after
the guard to avoid dereferencing a NULL start pointer.

Fixes libarchive/libarchive#2744

3 months agoFix incompatibility with Nettle 4.x 2858/head
FooIbar [Fri, 6 Feb 2026 12:52:25 +0000 (20:52 +0800)] 
Fix incompatibility with Nettle 4.x

3 months agoarchive_write: Fix crash on failure to convert WCS/UTF-8 pathname to MBS 2856/head
Brad King [Wed, 4 Feb 2026 21:35:03 +0000 (16:35 -0500)] 
archive_write: Fix crash on failure to convert WCS/UTF-8 pathname to MBS

If an entry pathname is set only by WCS or UTF-8, it may not have any
MBS representation in the archive's hdrcharset.  Do not crash or create
an archive with an empty pathname.  Furthermore, the entry pathname may
not have any MBS representation in the current locale.  Do not report a
`(null)` pathname in the error message.

3 months agoarchive_string_append_from_wcs: Fix silently lossy conversions on Windows
Brad King [Wed, 4 Feb 2026 21:42:26 +0000 (16:42 -0500)] 
archive_string_append_from_wcs: Fix silently lossy conversions on Windows

On Windows, since commit ae54394104 (Implement a string conversion
interface..., 2011-05-09, v3.0.0a~398), `archive_string_append_from_wcs`
no longer returns an error on use of replacement characters in non-C
locales.  Restore the error to avoid silent use of replacement
characters, and for consistency across platforms.