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

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

3 months agoUse __LA_MODE_T to avoid implicit int conversions (#2478)
Graham Percival [Sun, 6 Apr 2025 21:13:17 +0000 (14:13 -0700)] 
Use __LA_MODE_T to avoid implicit int conversions (#2478)

3 months agoFix missing newline at EOF (#2566)
Graham Percival [Sun, 6 Apr 2025 20:38:06 +0000 (13:38 -0700)] 
Fix missing newline at EOF (#2566)

3 months agoImprove lseek handling (#2564)
Tobias Stoeckmann [Sun, 6 Apr 2025 20:34:37 +0000 (22:34 +0200)] 
Improve lseek handling (#2564)

The skip functions are limited to 1 GB for cases in which libarchive
runs on a system with an off_t or long with 32 bits. This has negative
impact on 64 bit systems.

Instead, make sure that _all_ subsequent functions truncate properly.
Some of them already did and some had regressions for over 10 years.

Tests pass on Debian 12 i686 configured with --disable-largefile, i.e.
running with an off_t with 32 bits.

Casts added where needed to still pass MSVC builds.

---------

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
3 months agoReject bad hex values in xar checksums (#2479)
Graham Percival [Sun, 6 Apr 2025 07:29:16 +0000 (00:29 -0700)] 
Reject bad hex values in xar checksums (#2479)

Hex values should be A to F (and lower-case); if there's any other
letters, reject them.

3 months agoUse explicit casts for some functions (#2480)
Graham Percival [Sun, 6 Apr 2025 07:26:53 +0000 (00:26 -0700)] 
Use explicit casts for some functions (#2480)

3 months agoIssue 2548: Reading GNU sparse entries (#2558)
Tim Kientzle [Sun, 30 Mar 2025 16:26:25 +0000 (09:26 -0700)] 
Issue 2548: Reading GNU sparse entries (#2558)

My attempt to fix #2404 just made the confusion between the size of the
extracted file and the size of the contents in the tar archive worse
than it was before.

@ferivoz in #2557 showed that the confusion stemmed from a point where
we were setting the size in the entry (which is by definition the size
of the file on disk) when we read the `GNU.sparse.size` and
`GNU.sparse.realsize` attributes (which might represent the size on disk
or in the archive) and then using that to determine whether to read the
value in ustar header (which represents the size of the data in the
archive).

The confusion stems from three issues:
* The GNU.sparse.* fields mean different things depending on the version
of GNU tar used.
* The regular Pax `size` field overrides the value in the ustar header,
but the GNU sparse size fields don't always do so.
* The previous libarchive code tried to reconcile different size
information as we went along, which is problematic because the order in
which this information appears can vary.

This PR makes one big structural change: We now have separate storage
for every different size field we might encounter. We now just store
these values and record which one we saw. Then at the end, when we have
all the information available at once, we can use this data to determine
the size on disk and the size in the archive.

A few key facts about GNU sparse formats:

* GNU legacy sparse format: Stored all the relevant info in an extension
of the ustar header.
* GNU pax 0.0 format: Used `GNU.sparse.size` to store the size on disk
* GNU pax 0.1 format: Used `GNU.sparse.size` to store the size on disk
* GNU pax 1.0 format: Used `GNU.sparse.realsize` to store the size on
disk; repurposed `GNU.sparse.size` to store the size in the archive, but
omitted this in favor of the ustar size field when that could be used.

And of course, some key precedence information:
* Pax `size` field always overrides the ustar header size field.
* GNU sparse size fields override it ONLY when they represent the size
of the data in the archive.

Resolves #2548

3 months ago[cmake] Require CMake 3.17 or newer (#2556)
Christoph Grüninger [Sat, 29 Mar 2025 01:06:15 +0000 (02:06 +0100)] 
[cmake] Require CMake 3.17 or newer (#2556)

Remove code for older versions of CMake.
CMake 3.14 stopped running on Windows XP and Vista.

Fix detection of wcscmo, wcscpy, wcslen

3 months agoCommonalising time-related functions. (#2553)
ARJANEN Loïc Jean David [Fri, 28 Mar 2025 14:23:43 +0000 (15:23 +0100)] 
Commonalising time-related functions. (#2553)

Putting the time format conversion functions in one file and using the
common functions in the various formats.

3 months ago[cmake] Require minimum CMake version of 3.5 (#2555)
Christoph Grüninger [Wed, 26 Mar 2025 13:18:12 +0000 (14:18 +0100)] 
[cmake] Require minimum CMake version of 3.5 (#2555)

CMake 4.0 will be released soon and it refuses to accept a minimum
required version below 3.5 without additional flags.

3 months agoFix for the ZIP large file test (#2552)
ARJANEN Loïc Jean David [Tue, 25 Mar 2025 02:20:21 +0000 (03:20 +0100)] 
Fix for the ZIP large file test (#2552)

Making the ZIP large file test use the utility functions too.

3 months agoCMake: Replace CMAKE_COMPILER_IS_GNUCC with CMAKE_C_COMPILER_ID (#2550)
Peter Kokot [Sat, 22 Mar 2025 21:21:38 +0000 (22:21 +0100)] 
CMake: Replace CMAKE_COMPILER_IS_GNUCC with CMAKE_C_COMPILER_ID (#2550)

Hello,

- The `CMAKE_COMPILER_IS_*` variables are deprecated and
`CMAKE_C_COMPILER_ID` can be used in this case instead.
- The legacy `endif()` command argument also simplified to avoid
repeating the condition.

3 months agoOnly use S_ISSOCK if available. (#2543)
nia [Tue, 18 Mar 2025 13:17:03 +0000 (14:17 +0100)] 
Only use S_ISSOCK if available. (#2543)

Needed to build on OpenServer 5 Definitive 2018.

3 months agoMove archive_entry_set_digest() to public API (#2540)
Nicholas Vinson [Sun, 16 Mar 2025 23:37:47 +0000 (19:37 -0400)] 
Move archive_entry_set_digest() to public API (#2540)

Moving archive_entry_set_digest() to the public API simplifies porting
non-archive formats to archive formats while preserving supported
message digests specifically in cases where recomputing digests is not
viable.

3 months agoRemove extra newline from error messages (#2541)
Tobias Stoeckmann [Sun, 16 Mar 2025 22:33:05 +0000 (23:33 +0100)] 
Remove extra newline from error messages (#2541)

The lafe_errc function adds a newline by itself already, so do not
insert one into the message.

You can reproduce with the following commands:

```
touch archive.tar
bsdtar -xf archive.tar -C /non-existing
```

```
bsdtar --exclude ""
```

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
3 months agoFILE* seeking support (#2539)
ljdarj [Sat, 15 Mar 2025 18:17:27 +0000 (19:17 +0100)] 
FILE* seeking support (#2539)

Adding a seeker function to archive_read_open_FILE().

Fixes #437.

4 months agoCI: Update FreeBSD build environments (#2534)
Martin Matuška [Tue, 11 Mar 2025 13:15:49 +0000 (14:15 +0100)] 
CI: Update FreeBSD build environments (#2534)

FreeBSD 13.4 -> 13.5
FreeBSD 14.1 -> 14.2

4 months agofix CVE-2025-1632 and CVE-2025-25724 (#2532)
Peter Kästle [Mon, 10 Mar 2025 15:43:04 +0000 (16:43 +0100)] 
fix CVE-2025-1632 and CVE-2025-25724 (#2532)

Hi,

please find my approach to fix the CVE-2025-1632 and CVE-2025-25724
vulnerabilities in this pr.
As both error cases did trigger a NULL pointer deref (and triggered
hopefully everywhere a coredump), we can safely replace the actual
information by a predefined invalid string without breaking any
functionality.

---------

Signed-off-by: Peter Kaestle <peter@piie.net>
4 months agoarchive_version_details' update (#2349)
ljdarj [Sat, 8 Mar 2025 03:28:51 +0000 (04:28 +0100)] 
archive_version_details' update (#2349)

Adding missing librairies to `archive_version_details()`'s output. I put
"system" if the library doesn't give a way to query its version and
"bundled" if there's a choice between the system copy of a library and a
bundled one and we took the bundled copy (Only one library in that case,
libb2. Maybe also xxhash in the future?).

I would have a question for the Windows specialists though: is there a
way to query the interface version of a CNG cryptographic provider?
Because I know of a way for Crypto API providers but I haven't found any
for CNG ones, despite `<bcrypt.h>` having an interface version
structure.

Fixes #2300.

4 months agoMoving the tests' CRC-32 function to test_utils. (#2390)
ljdarj [Sat, 8 Mar 2025 03:21:23 +0000 (04:21 +0100)] 
Moving the tests' CRC-32 function to test_utils. (#2390)

Following up from #2284, putting the tests' CRC-32 implementation in
test_utils and having all tests use it.

4 months agoAvoid unreachable code in this test (#2528)
Tim Kientzle [Sat, 1 Mar 2025 17:06:31 +0000 (09:06 -0800)] 
Avoid unreachable code in this test (#2528)

As remarked in #2521, this test has unreachable code on Windows, which
triggers a build failure in development due to warnings-as-errors.
(Release versions should not have warnings-as-errors.)

4 months agoHandle ARCHIVE_FILTER_LZOP in archive_read_append_filter (#2519)
François Degros [Mon, 24 Feb 2025 15:01:39 +0000 (02:01 +1100)] 
Handle ARCHIVE_FILTER_LZOP in archive_read_append_filter (#2519)

Fixes #2513

4 months agoFixing up archive_read_format's man page. (#2518)
ljdarj [Sat, 22 Feb 2025 17:06:28 +0000 (18:06 +0100)] 
Fixing up archive_read_format's man page. (#2518)

Adding the requested updates to the man pages.

Fixes libarchive#2507.

5 months agoRemove dev_t and time_t from public API in 4.0 (#2392)
ljdarj [Sat, 25 Jan 2025 18:14:42 +0000 (19:14 +0100)] 
Remove dev_t and time_t from public API in 4.0 (#2392)

Removing dev_t and time_t from the public include files from 4.0 on and
updating some tests in consequence.

Fixes #2279 .

6 months agoCast (mode_t)mode for POSIX functions (#2476)
Graham Percival [Tue, 7 Jan 2025 00:44:40 +0000 (16:44 -0800)] 
Cast (mode_t)mode for POSIX functions (#2476)

6 months agoFix another GCC version detection error (#2474)
Mostyn Bramley-Moore [Wed, 1 Jan 2025 23:36:17 +0000 (00:36 +0100)] 
Fix another GCC version detection error (#2474)

This is another instance of the same bug that was fixed in #2472.

6 months agoSuppress macOS CC_MD5_* deprecation warnings in the autoconf build too (#2473)
Mostyn Bramley-Moore [Wed, 1 Jan 2025 23:30:37 +0000 (00:30 +0100)] 
Suppress macOS CC_MD5_* deprecation warnings in the autoconf build too (#2473)

This also limits the amount of code where deprecation warnings are
suppressed.

Previously these warnings were only suppressed in the cmake build.

6 months agoFix GCC version detection for __attribute__((deprecated)) (#2472)
Sam James [Wed, 1 Jan 2025 18:56:51 +0000 (18:56 +0000)] 
Fix GCC version detection for __attribute__((deprecated)) (#2472)

The #if condition as-written fails for any major >= 3 if minor < 1, e.g.
GCC 15.0 (while in development).

Use the idiom described in the GCC docs [0] to avoid this.

[0] https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html

Fixes: ab94a813b0f64cbc1bcb952bf55424a2d9c7f1d9
6 months agoFix a Y2038 bug by replacing `Int32x32To64` with regular multiplication (#2471)
Silent [Wed, 1 Jan 2025 16:31:35 +0000 (17:31 +0100)] 
Fix a Y2038 bug by replacing `Int32x32To64` with regular multiplication (#2471)

`Int32x32To64` macro internally truncates the arguments to int32, while
`time_t` is 64-bit on most/all modern platforms. Therefore, usage of
this macro creates a Year 2038 bug.

I detailed this issue a while ago in a writeup, and spotted the same
issue in this repository when updating the list of affected
repositories:
<https://cookieplmonster.github.io/2022/02/17/year-2038-problem/>

A few more notes:
1. I changed all uses of `Int32x32To64` en masse, even though at least
one of them was technically OK and used with int32 parameters only. IMO
better safe than sorry.
2. This is untested, but it's a small enough change that I hope the CI
success is a good enough indicator.

6 months agoFix compiler nitpicks (#2470)
Graham Percival [Tue, 31 Dec 2024 03:42:04 +0000 (19:42 -0800)] 
Fix compiler nitpicks (#2470)

6 months agoFix compiler nitpicks (#2469)
Graham Percival [Mon, 30 Dec 2024 21:31:48 +0000 (13:31 -0800)] 
Fix compiler nitpicks (#2469)

6 months agoFix MSVC conversion from DWORD to short warning (#2468)
Mostyn Bramley-Moore [Mon, 30 Dec 2024 16:32:39 +0000 (17:32 +0100)] 
Fix MSVC conversion from DWORD to short warning (#2468)

6 months agoFix MSVC zstd conversion from size_t to int warnings (#2467)
Mostyn Bramley-Moore [Mon, 30 Dec 2024 16:32:01 +0000 (17:32 +0100)] 
Fix MSVC zstd conversion from size_t to int warnings (#2467)

6 months agoDetect endianness at build time for common MSVC targets also (#2466)
Mostyn Bramley-Moore [Mon, 30 Dec 2024 16:31:14 +0000 (17:31 +0100)] 
Detect endianness at build time for common MSVC targets also (#2466)

This should now cover the most common build targets.

6 months agoFix compiler nitpicks (#2465)
Graham Percival [Mon, 30 Dec 2024 16:30:42 +0000 (08:30 -0800)] 
Fix compiler nitpicks (#2465)

6 months agoPrefer build-time endianness detection (#2464)
Mostyn Bramley-Moore [Mon, 30 Dec 2024 02:10:23 +0000 (03:10 +0100)] 
Prefer build-time endianness detection (#2464)

Endianness is easy to determine at runtime, but detecting this a single
time and then reusing the cached result might require API changes.

However we can use compile-time detection for some known compiler macros
without API changes fairly easily. Let's start by enabling this for
Clang and GCC.

6 months agoAdd more casts for %c, %o, and %x (#2463)
Graham Percival [Sun, 29 Dec 2024 18:20:24 +0000 (10:20 -0800)] 
Add more casts for %c, %o, and %x (#2463)

6 months agoSpelling fixes for func, struct, and macros (#2462)
Graham Percival [Sun, 29 Dec 2024 18:19:21 +0000 (10:19 -0800)] 
Spelling fixes for func, struct, and macros (#2462)

6 months agoAdd more casts for %o (#2461)
Graham Percival [Sun, 29 Dec 2024 18:18:06 +0000 (10:18 -0800)] 
Add more casts for %o (#2461)

6 months agoAdd straightforward casts for %o and %x (#2458)
Graham Percival [Sun, 29 Dec 2024 00:29:47 +0000 (16:29 -0800)] 
Add straightforward casts for %o and %x (#2458)

6 months ago7zip reader: add support for POWERPC filter for non-LZMA compressors (#2459)
Mostyn Bramley-Moore [Sat, 28 Dec 2024 23:36:01 +0000 (00:36 +0100)] 
7zip reader: add support for POWERPC filter for non-LZMA compressors (#2459)

This new test archive contains a C hello world executable built like so
on a ubuntu 24.04 machine:
```
#include <stdio.h>

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=deflate -mf=ppc
libarchive/test/test_read_format_7zip_deflate_powerpc.7z hw-powerpc`

This test fails in the first commit in this PR, and passes in the second
commit.

6 months agoFix format strings (#2457)
Graham Percival [Sat, 28 Dec 2024 19:03:17 +0000 (11:03 -0800)] 
Fix format strings (#2457)

6 months agoAdd tar/test/test_list_item (#2454)
Graham Percival [Sat, 28 Dec 2024 19:01:19 +0000 (11:01 -0800)] 
Add tar/test/test_list_item (#2454)

6 months agoFix the test for NOABSOLUTEPATHS (#2456)
Tim Kientzle [Fri, 27 Dec 2024 23:51:33 +0000 (15:51 -0800)] 
Fix the test for NOABSOLUTEPATHS (#2456)

The test inadvertently tried to manipulate the wrong archive at one
point.

6 months agotar: fix bug when -s/a/b/ used more than once with b flag (#2435)
Stephane Chazelas [Fri, 27 Dec 2024 23:20:16 +0000 (23:20 +0000)] 
tar: fix bug when -s/a/b/ used more than once with b flag (#2435)

When the -s/regexp/replacement/ option was used with the b flag more
than once, the result of the previous substitution was appended to the
previous subject instead of replacing it. Fixed it by making sure the
subject is made the empty string before the call to realloc_strcat().
That in effect makes it more like a realloc_strcpy(), but creating a new
realloc_strcpy() function for that one usage doesn't feel worth it.

Resolves Issue libarchive/libarchive#2414

Co-authored-by: Stephane Chazelas <stephane@chazelas.org>
6 months agoFix -Werror=warning error and wrap some INSTALL directives with an ENABLE_INSTALL...
Zeun [Fri, 27 Dec 2024 20:53:13 +0000 (09:53 +1300)] 
Fix -Werror=warning error and wrap some INSTALL directives with an ENABLE_INSTALL guard (#2397)

1. Fixes build when compiling without ZLIB/BZIP/LZMA `char finishing`
2. All INSTALL directives are now guarded by ENABLE_INSTALL

6 months agoci: use at most the number of make threads as there are cores on mac and linux github...
Mostyn Bramley-Moore [Fri, 27 Dec 2024 20:40:47 +0000 (21:40 +0100)] 
ci: use at most the number of make threads as there are cores on mac and linux github runners (#2437)

We previously told make to run as many threads as it likes on these CI
jobs, but that might sometimes hit resource limits like RAM or the
allowed number of open files.

These numbers were found experimentally by using `sysctl -n hw.ncpu` on
mac and `nproc` on linux.

6 months agoFix remaining TODOs in test_stdio.c (#2444)
Graham Percival [Fri, 27 Dec 2024 20:38:03 +0000 (12:38 -0800)] 
Fix remaining TODOs in test_stdio.c (#2444)

6 months agoRemove unnecessary semicolons (#2450)
Graham Percival [Wed, 25 Dec 2024 17:35:54 +0000 (09:35 -0800)] 
Remove unnecessary semicolons (#2450)

6 months agoRemove unreachable 'break' statements (#2451)
Graham Percival [Wed, 25 Dec 2024 17:33:11 +0000 (09:33 -0800)] 
Remove unreachable 'break' statements (#2451)

6 months agoFix %d -> %u for unsigned int from i4le() (#2448)
Graham Percival [Tue, 24 Dec 2024 23:27:26 +0000 (15:27 -0800)] 
Fix %d -> %u for unsigned int from i4le() (#2448)

`i4le()` returns an unsigned int, so `'%d'` is incorrect.

Reported by `clang -Wformat`. (Many more such fixes to come, but this is
the simplest set of them.)

6 months agoFix CRLF line endings in source files (#2449)
Graham Percival [Tue, 24 Dec 2024 23:25:53 +0000 (15:25 -0800)] 
Fix CRLF line endings in source files (#2449)

6 months agoReject relative path for test refdir (#2445)
Graham Percival [Tue, 24 Dec 2024 19:51:50 +0000 (11:51 -0800)] 
Reject relative path for test refdir (#2445)

6 months agoFix a few clang nitpicks (#2447)
Graham Percival [Tue, 24 Dec 2024 19:50:19 +0000 (11:50 -0800)] 
Fix a few clang nitpicks (#2447)

Fixes warnings found by:
```
-Wformat-non-iso
-Wnewline-eof
-Wmissing-variable-declarations
```

6 months agoFix some TODOs in tar/test/test_stdio.c (#2442)
Graham Percival [Thu, 19 Dec 2024 22:24:57 +0000 (14:24 -0800)] 
Fix some TODOs in tar/test/test_stdio.c (#2442)

6 months agoRemove liblzmadec remnants (#2436)
Mostyn Bramley-Moore [Sun, 15 Dec 2024 22:14:57 +0000 (23:14 +0100)] 
Remove liblzmadec remnants (#2436)

It looks like support for this library was removed in 2016, but we still
had some unused cmake code and a dead preprocessor block.

6 months ago7zip reader: add LZMA + RISCV BCJ filter (#2403)
Mostyn Bramley-Moore [Sun, 15 Dec 2024 22:12:02 +0000 (23:12 +0100)] 
7zip reader: add LZMA + RISCV BCJ filter (#2403)

7-Zip 24.05 and liblzma 5.5.1alpha added a RISC-V BCJ filter. Let's
enable this combination if we can.

Note that this does not allow the use of the RISC-V filter with other
compressors.

6 months ago7zip writer: support multithreaded zstandard compression (#2391)
Mostyn Bramley-Moore [Sun, 15 Dec 2024 22:10:17 +0000 (23:10 +0100)] 
7zip writer: support multithreaded zstandard compression (#2391)

Command example:
bsdtar -cavf /tmp/foo.7z --options='compression=zstd,threads=4' *

7 months agoRemove unnecessary HAVE_LZMA_FILTER_ARM64 feature check (#2433)
Mostyn Bramley-Moore [Wed, 11 Dec 2024 04:35:16 +0000 (05:35 +0100)] 
Remove unnecessary HAVE_LZMA_FILTER_ARM64 feature check (#2433)

It is sufficent to use HAVE_LZMA_H and then check for macros defined in
lzma.h

7 months agoHandle truncation in the middle of a GNU long linkname (#2422)
Tim Kientzle [Tue, 10 Dec 2024 05:09:29 +0000 (21:09 -0800)] 
Handle truncation in the middle of a GNU long linkname (#2422)

Thanks to gbdngb12 김동건 for reporting this.

Resolves Issue #2415