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

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

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

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

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

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

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

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

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

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

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

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

7 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' *

8 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

8 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

8 months agoci: make skipped tests more obvious (#2430)
Mostyn Bramley-Moore [Mon, 9 Dec 2024 02:08:34 +0000 (03:08 +0100)] 
ci: make skipped tests more obvious (#2430)

Previously skipped tests were reported like this when running the *_test
binaries:
```
 4: test_acl_platform_nfs4                                          ok (S)
```

Let's make this more obvious:
```
  4: test_acl_platform_nfs4                                         skipped
```

8 months agoReport skipped tests to cmake/ctest (#2429)
Mostyn Bramley-Moore [Mon, 9 Dec 2024 02:07:49 +0000 (03:07 +0100)] 
Report skipped tests to cmake/ctest (#2429)

This plumbing is required for cmake/ctest to recognise and report
skipped tests.

Now skipped tests in cmake ci jobs are reported like so:
```
          Start   7: libarchive_test_acl_platform_posix1e_read
    7/785 Test   #7: libarchive_test_acl_platform_posix1e_read ................................***Skipped   0.02 sec
```

And there is a list of skipped tests shown at the end of the test run.

8 months agoci: speed up windows/mingw build by using multiple make jobs (#2428)
Mostyn Bramley-Moore [Sun, 8 Dec 2024 00:39:46 +0000 (01:39 +0100)] 
ci: speed up windows/mingw build by using multiple make jobs (#2428)

This decreases the "Install library dependencies" step duration from
~4min to ~2min, and the "Build" step duration from ~10min to ~4min.

8 months agoci: make autoconf look for headers and libraries in /opt/homebrew if those directorie...
Mostyn Bramley-Moore [Sat, 7 Dec 2024 23:11:19 +0000 (00:11 +0100)] 
ci: make autoconf look for headers and libraries in /opt/homebrew if those directories exist (#2427)

Prior to this change, the ci autoconf jobs weren't looking for homebrew
headers or libraries unless pkg-config was used, so for example the
"MacOS (autotools)" ci job wasn't testing lz4 or zstd code.

Relates to #2426.

8 months agoci: log bsdtar's version text, so we can see which support libraries were used (...
Mostyn Bramley-Moore [Sat, 7 Dec 2024 23:10:42 +0000 (00:10 +0100)] 
ci: log bsdtar's version text, so we can see which support libraries were used (#2426)

A few of libarchive's CI jobs don't find all the local support libraries
that they could be using. This change makes it easier to see which of
them are used.

8 months agoci: find liblzma >= 5.6.3 on windows msvc tests (#2421)
Mostyn Bramley-Moore [Sat, 7 Dec 2024 03:56:06 +0000 (04:56 +0100)] 
ci: find liblzma >= 5.6.3 on windows msvc tests (#2421)

We currently use XZ Utils 5.6.3 on windows CI jobs, but the Windows
(msvc)
job which uses cmake seems to only be looking for the old library name,
liblzma.lib:

```
-- Looking for lzma_auto_decoder in C:/Program Files (x86)/xz/lib/liblzma.lib
-- Looking for lzma_auto_decoder in C:/Program Files (x86)/xz/lib/liblzma.lib - not found
-- Looking for lzma_easy_encoder in C:/Program Files (x86)/xz/lib/liblzma.lib
-- Looking for lzma_easy_encoder in C:/Program Files (x86)/xz/lib/liblzma.lib - not found
-- Looking for lzma_lzma_preset in C:/Program Files (x86)/xz/lib/liblzma.lib
-- Looking for lzma_lzma_preset in C:/Program Files (x86)/xz/lib/liblzma.lib - not found
-- Could NOT find LibLZMA (missing: LIBLZMA_HAS_AUTO_DECODER LIBLZMA_HAS_EASY_ENCODER LIBLZMA_HAS_LZMA_PRESET) (found version "5.6.3")
```

We need to update build/ci/github_actions/ci.cmd to look for lzma.lib
instead.

8 months agoSpelling fixes (#2412)
Graham Percival [Fri, 6 Dec 2024 16:00:03 +0000 (08:00 -0800)] 
Spelling fixes (#2412)

8 months agoCheck for tcgetattr / tcsetattr before using it for readpassphrase implementation...
Julian Uy [Fri, 6 Dec 2024 15:58:58 +0000 (09:58 -0600)] 
Check for tcgetattr / tcsetattr before using it for readpassphrase implementation (#2424)

This is mainly for non-cygwin newlib platforms that don't have tcgetattr
/ tcsetattr implemented

8 months agoAdd missing definition for getline polyfill (#2425)
Julian Uy [Fri, 6 Dec 2024 15:57:27 +0000 (09:57 -0600)] 
Add missing definition for getline polyfill (#2425)

The fallback for when `getline` is not implemented in libc was not
compiling due to the fact that the definition for it was missing, so add
the definition.

8 months agobsdtar.1: Mention rar support + manual page polish (#2423)
Alexander Ziaee [Fri, 6 Dec 2024 15:50:06 +0000 (10:50 -0500)] 
bsdtar.1: Mention rar support + manual page polish (#2423)

I have been using this for years without realizing it decompresses rar.

+ add rar to supported decompression formats
+ use section references to link sections (this makes them clickable in
GUIs)
+ add paragraph breaks for consistent spacing
+ pdtar is not this program, so use Sy per mdoc style guide
+ do almost the same in reverse for bsdtar
+ remove parenthetical around a complete sentance

Thank you so much, this is wonderful software.

8 months agoTest with XZ Utils 5.6.3 on windows CI jobs (#2417)
Mostyn Bramley-Moore [Sun, 1 Dec 2024 23:29:46 +0000 (00:29 +0100)] 
Test with XZ Utils 5.6.3 on windows CI jobs (#2417)

This change fixes the autotools build to work with xz-utils 5.6.3, which
changed library names on windows, and fixes a couple of tests that I
noticed had dependencies on liblzma.

8 months agonit(tar): fix typo (#2420)
MithicSpirit [Sun, 1 Dec 2024 03:21:45 +0000 (22:21 -0500)] 
nit(tar): fix typo (#2420)

8 months agoMoving the tests' integer reading functions to test_utils. (#2410)
ljdarj [Sun, 17 Nov 2024 01:42:27 +0000 (02:42 +0100)] 
Moving the tests' integer reading functions to test_utils. (#2410)

Moving the tests' integer reading functions to test_utils so that they
all use the same as well as moving the few using the archive_endian
functions over to the test_utils helper.

Follow-up from libarchive#2390.

9 months agoIgnore ustar size when pax size is present (#2405)
Tim Kientzle [Wed, 6 Nov 2024 21:21:54 +0000 (13:21 -0800)] 
Ignore ustar size when pax size is present (#2405)

When the pax `size` field is present, we should ignore the size value in
the ustar header. In particular, this fixes reading pax archives created
by GNU tar with entries larger than 8GB.

Note: This doesn't impact reading pax archives created by libarchive
because libarchive uses tar extensions to store an accurate large size
field in the ustar header. GNU tar instead strictly follows ustar in
this case, which prevents it from storing accurate sizes in the ustar
header.

Resolves #2404

9 months ago7zip reader: add SPARC filter support for non-LZMA compressors (#2399)
Mostyn Bramley-Moore [Tue, 29 Oct 2024 02:29:23 +0000 (03:29 +0100)] 
7zip reader: add SPARC filter support for non-LZMA compressors (#2399)

These two new test archives contain 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;
}
```

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

The two test archives that contain this executable were created like so,
using the https://github.com/tehmul/p7zip-zstd fork of 7-Zip:
`7z a -t7z -m0=zstd -mf=SPARC
libarchive/test/test_read_format_7zip_zstd_sparc.7z hw-sparc64`
`7z a -t7z -m0=lzma2 -mf=SPARC
libarchive/test/test_read_format_7zip_lzma2_sparc.7z hw-sparc64`

Two test files are required, because the 7zip reader code has two
different paths, one for lzma and one for all other compressors.

The test_read_format_7zip_lzma2_sparc test is expected to pass, because
LZMA BCJ filters are implemented in liblzma.

The test_read_format_7zip_zstd_sparc test is expected to fail in the
first commit, because libarchive does not currently implement the SPARC
BCJ filter. The second commit will make test_read_format_7zip_zstd_sparc
pass.

9 months agoRevert "Use proper Create OS value on Windows to fix archive charset detection (...
Tim Kientzle [Mon, 28 Oct 2024 02:34:51 +0000 (19:34 -0700)] 
Revert "Use proper Create OS value on Windows to fix archive charset detection (#2240) (#2401)

Two problems are prompting this revert:

* In order to change the Create OS value to "Windows", we would need to
record other data (such as `external_attributes`) in Windows format as
well.

* Changing the Create OS value doesn't actually fix the
filename-encoding issue that originally motivated this PR

This reverts commit 755af84301adc4262722a4c88671a8d0a1c83fae.

9 months agoRename bsdtar test_extract_tar_absolute_paths source file for consistency (#2400)
Mostyn Bramley-Moore [Sun, 27 Oct 2024 15:43:59 +0000 (16:43 +0100)] 
Rename bsdtar test_extract_tar_absolute_paths source file for consistency (#2400)

The `-P` flag is uppercase, so the test file should be named
test_option_P_upper.c for consistency with the other test files in this
directory.

Sorry about the noise.

9 months agotests: redirect stdout in one call in test_extract_tar_absolute_paths (#2386) 2394/head
Martin Matuška [Fri, 25 Oct 2024 17:45:28 +0000 (19:45 +0200)] 
tests: redirect stdout in one call in test_extract_tar_absolute_paths (#2386)

This redirects the message "Removing leading '/' from member names"
from stderr to a file in one case.

9 months agoFix tests added in #2284 (#2387)
Martin Matuska [Wed, 23 Oct 2024 16:47:32 +0000 (18:47 +0200)] 
Fix tests added in #2284 (#2387)

9 months agoRevert "add `--mac-metadata` test for `--format zip` - see #2041 (#2045)"
Martin Matuska [Wed, 23 Oct 2024 16:45:23 +0000 (18:45 +0200)] 
Revert "add `--mac-metadata` test for `--format zip` - see #2041 (#2045)"

This reverts commit ea56096020e2c6c764052adfab63e11fd745f9de.

9 months agoadd `--mac-metadata` test for `--format zip` - see #2041 (#2045)
nielash [Tue, 22 Oct 2024 09:16:55 +0000 (05:16 -0400)] 
add `--mac-metadata` test for `--format zip` - see #2041 (#2045)

Submitting this test at the request of @kientzle on issue #2041.

Note that failure is currently expected, as the feature it tests is not
yet implemented!

9 months agowrite_xar: move libxml2 behind an abstraction layer (#1849)
Dustin L. Howett [Tue, 22 Oct 2024 09:10:50 +0000 (04:10 -0500)] 
write_xar: move libxml2 behind an abstraction layer (#1849)

This commit prepares the XAR writer for another XML writing backend.

Almost everything in this changeset leaves the code identical to how
it started, except for a new layer of indirection between the xar writer
and the XML writer.

The things that are not one-to-one renames include:
- The removal of `UTF8Toisolat1` for the purposes of validating UTF-8
- The writer code made a copy of every filename for the purposes of
  checking whether it was Latin-1 stored as UTF-8. In xar, Non-Latin-1
  gets stored Base64-encoded.
- I've replaced this use because (1) it was inefficient and (2)
  `UTF8Toisolat1` is a `libxml2` export.
- The new function has slightly different results than the one it is
  replacing for invalid UTF-8. Namely, it treats illegal UTF-8 "overlong"
  encodings of Latin-1 codepoints as _invalid_. It operates on the principle
  that we can determine whether something is Latin-1 based entirely on how
  long the sequence is expected to be.
- The move of `SetIndent` to before `StartDocument`, which the
  abstraction layer immediately undoes. This is to accommodate XML writers
  that require indent to be set _before_ the document starts.

9 months ago7zip writer: initial support for zstandard compression (#2137)
Mostyn Bramley-Moore [Tue, 22 Oct 2024 09:01:55 +0000 (11:01 +0200)] 
7zip writer: initial support for zstandard compression (#2137)

This is intended to be compatible with:
* https://github.com/mcmilk/7-Zip-zstd
* https://github.com/tehmul/p7zip-zstd

9 months agoAdding XZ, LZMA, ZSTD and BZIP2 support to ZIP writer (#2284)
ljdarj [Tue, 22 Oct 2024 08:58:22 +0000 (10:58 +0200)] 
Adding XZ, LZMA, ZSTD and BZIP2 support to ZIP writer (#2284)

PPMD may come later but I'd rather first iron out style issues with the
ones needing only to wire up libraries already-used in Libarchive before
going at the ones possibly requiring implementing algorithms as well.

Closes #1046 and resolves #1179.

9 months agoUse proper Create OS value on Windows to fix archive charset detection (#2240)
unxed [Tue, 22 Oct 2024 08:56:19 +0000 (10:56 +0200)] 
Use proper Create OS value on Windows to fix archive charset detection (#2240)

See https://sourceforge.net/p/sevenzip/bugs/2463

9 months agoReintroduce size_t cast to clarify the use of a u32 shift on a u64 arg (#2383)
Dustin L. Howett [Tue, 22 Oct 2024 08:52:19 +0000 (03:52 -0500)] 
Reintroduce size_t cast to clarify the use of a u32 shift on a u64 arg (#2383)

Regressed in #2285

9 months agoVarious small fixes for Cygwin, Haiku, OpenIndiana (#2346)
vcoxvco [Mon, 14 Oct 2024 15:44:17 +0000 (17:44 +0200)] 
Various small fixes for Cygwin, Haiku, OpenIndiana (#2346)

Cygwin 3.5.4 (same applies for 3.5.3),
I get a compile error as shown below after a simple ./configure and
make. Adding <windef.h> solves the problem.

Co-authored-by: vco <god@universe.sys>
9 months agotests: use const char instead of char in one case (#2381)
Martin Matuška [Sun, 13 Oct 2024 20:41:06 +0000 (22:41 +0200)] 
tests: use const char instead of char in one case (#2381)

Found in test_extract_cpio_absolute_paths.c when compiling FreeBSD base

9 months agoIgnore checksum mismatches when fuzzing tar archives (#2378)
Tim Kientzle [Sun, 13 Oct 2024 07:42:38 +0000 (00:42 -0700)] 
Ignore checksum mismatches when fuzzing tar archives (#2378)

This should speed up fuzzing just a bit, so we
can find more bugs!

9 months agoCI: Bump the all-actions group across 1 directory with 4 updates (#2379)
dependabot[bot] [Sun, 13 Oct 2024 07:42:01 +0000 (09:42 +0200)] 
CI: Bump the all-actions group across 1 directory with 4 updates (#2379)

Bumps the all-actions group with 4 updates:

actions/checkout from 4.1.6 to 4.2.1
actions/upload-artifact from 4.3.3 to 4.4.3
github/codeql-action from 3.25.6 to 3.26.12
ossf/scorecard-action from 2.3.3 to 2.4.0

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
9 months agoIncrease the hole size for this test to 32MiB (#2380)
Tim Kientzle [Sun, 13 Oct 2024 07:35:17 +0000 (00:35 -0700)] 
Increase the hole size for this test to 32MiB (#2380)

APFS on macOS 15 seems to have a higher threshold for creating sparse
files.

9 months agoConvert the tools and respective tests to SPDX (#2317)
Emil Velikov [Sun, 13 Oct 2024 03:54:16 +0000 (04:54 +0100)] 
Convert the tools and respective tests to SPDX (#2317)

This is the first part of converting the project to use SPDX license
identifiers instead using the verbose license text.

The patches are semi-automated and I've went through manually to ensure
no license changes were made. That said, I would welcome another pair of
eyes, since I am only human.

See https://github.com/libarchive/libarchive/issues/2298

---------

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
9 months agoUpdate archive_private to avoid template keyword (#2342)
Christian Schmitz [Sun, 13 Oct 2024 00:47:30 +0000 (02:47 +0200)] 
Update archive_private to avoid template keyword (#2342)

People really should never, ever, ever use libarchive internal headers.  And they definitely should not expect libarchive internal headers to work in a C++ compiler.  (C++ and C are really just not that compatible.)

However, people do a lot of things they shouldn't:  Avoid the reserved C++ keyword `template`

9 months agoconfigure.ac,CMakeLists.txt: Add libbsd on Haiku for readpassphrase (#2352)
vcoxvco [Sun, 13 Oct 2024 00:44:32 +0000 (02:44 +0200)] 
configure.ac,CMakeLists.txt: Add libbsd on Haiku for readpassphrase (#2352)

Followup from #2346

Add libbsd to make/cmake configuration for linking readpassphrase on
Haiku.
Maybe there is a better way to do this for cmake, I'm not that familiar
with it.

Co-authored-by: vco <god@universe.sys>
9 months agoCI: Update build environments (#2373)
Martin Matuška [Sat, 12 Oct 2024 16:31:20 +0000 (18:31 +0200)] 
CI: Update build environments (#2373)

FreeBSD 13.3 -> 13.4
FreeBSD 14.0 -> 14.1
Ubuntu 22.04 -> 24.04

9 months agoFix two leaks in tar header parsing (#2377)
Tim Kientzle [Sat, 12 Oct 2024 11:54:23 +0000 (04:54 -0700)] 
Fix two leaks in tar header parsing (#2377)

OSS-Fuzz found two places where an error return would bypass cleaning up
a local allocation.

Credit: OSS-Fuzz

9 months agotests: change file format from dos to unix in one test file (#2376)
Martin Matuška [Sat, 12 Oct 2024 03:54:59 +0000 (05:54 +0200)] 
tests: change file format from dos to unix in one test file (#2376)

10 months ago[7zip] Read/write symlink paths as UTF-8 (#2252)
Duncan Horn [Fri, 11 Oct 2024 06:30:25 +0000 (23:30 -0700)] 
[7zip] Read/write symlink paths as UTF-8 (#2252)

I previously tried to find documentation on how symlinks are expected to
be stored in 7zip files, however the best reference I could find was
[here](https://py7zr.readthedocs.io/en/latest/archive_format.html). That
site suggests that symlink paths are stored as UTF-8 encoded strings:

10 months agoUpdate RAR5 code to report encryption (#2096)
Duncan Horn [Fri, 11 Oct 2024 06:25:47 +0000 (23:25 -0700)] 
Update RAR5 code to report encryption (#2096)

Currently, the RAR5 code always reports
`ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED` for
`archive_read_has_encrypted_entries`, nor does it set any of the
entry-specific properties, even though it has enough information to
properly report this information. Accurate reporting of encryption is
super useful for applications because reporting an error message such as
"the archive is encrypted, but we don't currently support encryption" is
a lot better than a not generally useful `errno` value and a
non-localizable error string with a confusing and unpredictable error
message.

Fixes #1661

10 months agoChange to Windows absolute symlinks. (#2362)
ljdarj [Fri, 11 Oct 2024 06:18:55 +0000 (08:18 +0200)] 
Change to Windows absolute symlinks. (#2362)

Change to read absolute symlinks as verbatim paths instead of NT paths:
as far as I can see, libarchive can deal with verbatim paths while it
can't with NT ones.

Fixes #2274.

10 months agoconfigure.ac: remove incorrect 4th argument to `AC_CHECK_FUNCS` (#2334)
Michał Górny [Fri, 11 Oct 2024 06:17:01 +0000 (08:17 +0200)] 
configure.ac: remove incorrect 4th argument to `AC_CHECK_FUNCS` (#2334)

Remove the incorrect 4th argument from `AC_CHECK_FUNCS` calls. The macro
uses only three arguments, so it was ignored anyway. Furthermore, in at
least once instance it was wrong -- due to a typo in `attr/xatr.h`
header name.

10 months agoDon't crash on truncated tar archives (#2364)
Tim Kientzle [Fri, 11 Oct 2024 06:16:12 +0000 (23:16 -0700)] 
Don't crash on truncated tar archives (#2364)

The tar header parsing overhaul in #2127 introduced a systematic
mishandling of truncated files: the code incorrectly checks for whether
a given read operation failed, and ends up dereferencing a NULL pointer
in this case. I've gone back and double-checked how
`__archive_read_ahead` actually works (it returns NULL precisely when it
was unable to satisfy the read request) and reworked the error handling
for each call to this function in archive_read_support_format_tar.c

Resolves #2353
Resolves https://issues.oss-fuzz.com/issues/42537231

10 months agoSanity-check gzip header field length (#2366)
Tim Kientzle [Fri, 11 Oct 2024 06:14:58 +0000 (23:14 -0700)] 
Sanity-check gzip header field length (#2366)

OSS-Fuzz managed to construct a small gzip input that decompresses into
another gzip input with an extremely large filename field. This causes
libarchive to hang processing the inner gzip.

Address this by rejecting any gzip input where the filename or comment
fields exceed 1MiB.

Credit: OSS-Fuzz

10 months agoClarify crc32 variable names (#2367)
Tim Kientzle [Fri, 11 Oct 2024 06:13:00 +0000 (23:13 -0700)] 
Clarify crc32 variable names (#2367)

No functional change, just a tiny style improvement.

Use `crc32_computed` to refer to the crc32 that the reader has computed
and `crc32_read` to refer to the value that we read from the archive.
That hopefully makes this code a tiny bit easier to follow. (It confused
me recently when I was double-checking something in this area, so I
thought an improvement here might help others.)

10 months agoFix error message printing (#2368)
Tim Kientzle [Fri, 11 Oct 2024 06:11:43 +0000 (23:11 -0700)] 
Fix error message printing (#2368)

We always print the error message with or without -v, but for some
reason, we were omitting the path being processed. Simplify so that we
always print the full error including context.

10 months agoDon't use Windows bcrypt when building for Windows XP or older (#2374)
Steve Lhomme [Wed, 9 Oct 2024 04:06:57 +0000 (21:06 -0700)] 
Don't use Windows bcrypt when building for Windows XP or older (#2374)

The header may be detected but we can't use the calls.

The same check is already done in many places but not all of them.

10 months agobsdcpio should exit with an error code if an entry can't be extracted (#2371)
Mostyn Bramley-Moore [Mon, 7 Oct 2024 15:51:17 +0000 (17:51 +0200)] 
bsdcpio should exit with an error code if an entry can't be extracted (#2371)

For example if --insecure is not specified, and one of the security
checks fails.

10 months agoAdd absolute path test for bsdtar (#2370)
Mostyn Bramley-Moore [Mon, 7 Oct 2024 03:35:28 +0000 (05:35 +0200)] 
Add absolute path test for bsdtar (#2370)

Check that extracting archive entries with absolute paths uses mangled
relative paths unless -P / --absolute-paths is specified.

10 months agoSimplify tests added in #2363, use testworkdir (#2369)
Mostyn Bramley-Moore [Mon, 7 Oct 2024 03:34:58 +0000 (05:34 +0200)] 
Simplify tests added in #2363, use testworkdir (#2369)

10 months agoFix pathname overwrite in header_old_tar() (#2360)
Martin Matuška [Mon, 7 Oct 2024 03:31:38 +0000 (05:31 +0200)] 
Fix pathname overwrite in header_old_tar() (#2360)

Fixes #2359

10 months agoMiscellaneous code cleanup (#2285)
Dag-Erling Smørgrav [Fri, 4 Oct 2024 15:45:58 +0000 (17:45 +0200)] 
Miscellaneous code cleanup (#2285)

This fixes various code quality issues I encountered while chasing a
memory leak reported by test automation. I failed to reproduce the
memory leak, but I hope you find this useful nonetheless.

10 months agoFix ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS on windows (#2363)
Mostyn Bramley-Moore [Fri, 4 Oct 2024 15:36:56 +0000 (17:36 +0200)] 
Fix ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS on windows (#2363)

10 months agoReenable CI tests for MSVC (#2356)
Mostyn Bramley-Moore [Mon, 30 Sep 2024 04:36:48 +0000 (06:36 +0200)] 
Reenable CI tests for MSVC (#2356)

These were disabled when migrating from Cirrus CI. Let's enable them for
github workflows, disable any failing tests on this configuration and
leave TODO notes to fix them.

This was the only failure that I found:
```
  684/764 Test #684: bsdtar_test_option_ignore_zeros_mode_c ...................................***Failed    0.10 sec

  If tests fail or crash, details will be in:
     C:\Users\RUNNER~1\AppData\Local\Temp/bsdtar_test.exe.2024-09-29T11.42.13-000

  Reference files will be read from: D:/a/libarchive/libarchive/tar/test
  Running tests on: "D:\a\libarchive\libarchive\build_ci\cmake\bin\Release\bsdtar.exe"
  Exercising: bsdtar 3.8.0 - libarchive 3.8.0dev zlib/1.3 liblzma/5.4.4 bz2lib/1.1.0 libzstd/1.5.5

   39: test_option_ignore_zeros_mode_c
  D:\a\libarchive\libarchive\tar\test\test_option_ignore_zeros.c(99): File should be empty: test-c.err
      File size: 112
      Contents:
  0000 62 73 64 74 61 72 2e 65 78 65 3a 20 61 3a 20 43 bsdtar.exe: a: C
  0010 61 6e 27 74 20 74 72 61 6e 73 6c 61 74 65 20 75 an't translate u
  0020 6e 61 6d 65 20 27 28 6e 75 6c 6c 29 27 20 74 6f name '(null)' to
  0030 20 55 54 46 2d 38 0d 0a 62 73 64 74 61 72 2e 65  UTF-8..bsdtar.e
  0040 78 65 3a 20 62 3a 20 43 61 6e 27 74 20 74 72 61 xe: b: Can't tra
  0050 6e 73 6c 61 74 65 20 75 6e 61 6d 65 20 27 28 6e nslate uname '(n
  0060 75 6c 6c 29 27 20 74 6f 20 55 54 46 2d 38 0d 0a ull)' to UTF-8..

  Totals:
    Tests run:                1
    Tests failed:             1
    Assertions checked:      21
    Assertions failed:        1
    Skips reported:           0
```

10 months agoRemove two unnecessary strings from the tar state (#2345)
Tim Kientzle [Wed, 25 Sep 2024 02:12:11 +0000 (19:12 -0700)] 
Remove two unnecessary strings from the tar state (#2345)

`pax_global` is not used at all and can be removed.

`longname` is only used locally within one function, so convert it to a
local variable there.

10 months agoClean up linkpath between entries (#2343)
Tim Kientzle [Sun, 22 Sep 2024 23:06:34 +0000 (16:06 -0700)] 
Clean up linkpath between entries (#2343)

PR #2127 failed to clean up the linkpath storage between entries. As a
result, after the first hard/symlink entry in a pax format archive, all
subsequent entries would get the same link information.

I'm really unsure how this bug failed to trip CI. I'll do some digging
in the test suite before I merge this.

Resolves #2331 , #2337

P.S. Thanks to Brad King for noting that the linkpath wasn't being
managed correctly, which was a big hint for me.

10 months agotar/write.h: Support `sys/xattr.h` (#2335) 2344/head
Michał Górny [Sat, 21 Sep 2024 02:44:06 +0000 (04:44 +0200)] 
tar/write.h: Support `sys/xattr.h` (#2335)

Synchronize the last use of `attr/xattr.h` to support using
`sys/xattr.h` instead. The former header is deprecated on GNU/Linux, and
this replacement makes it possible to build libarchive without the
`attr` package.

10 months agotar: fix memory leaks when processing symlinks or parsing pax headers (#2338)
Brad King [Fri, 20 Sep 2024 12:11:43 +0000 (08:11 -0400)] 
tar: fix memory leaks when processing symlinks or parsing pax headers (#2338)

Fix memory leaks introduced by #2127:

* `struct tar` member `entry_linkpath` was moved at the same time as
   other members were removed, but its cleanup was accidentally removed
   with the others.

* `header_pax_extension` local variable `attr_name` was not cleaned up.

Resolves #2336

10 months agoBe more cautious about parsing ISO-9660 timestamps (#2330)
Tim Kientzle [Fri, 20 Sep 2024 05:20:02 +0000 (22:20 -0700)] 
Be more cautious about parsing ISO-9660 timestamps (#2330)

Some ISO images don't have valid timestamps for the root directory
entry. Parsing such timestamps can generate nonsensical results, which
in one case showed up as an unexpected overflow on a 32-bit system.

Add some validation logic that can check whether a 7-byte or 17-byte
timestamp is reasonable-looking, and use this to ignore invalid
timestamps in various locations. This also requires us to be a little
more careful about tracking which timestamps are actually known.

Resolves issue #2329

10 months agoLibarchive 3.8.0dev
Martin Matuska [Fri, 13 Sep 2024 21:13:01 +0000 (23:13 +0200)] 
Libarchive 3.8.0dev

10 months agoRelease 3.7.5 release v3.7.5
Martin Matuska [Fri, 13 Sep 2024 20:20:55 +0000 (22:20 +0200)] 
Release 3.7.5

10 months agocmake: do not require zlib (#2327)
Mostyn Bramley-Moore [Fri, 13 Sep 2024 19:28:05 +0000 (21:28 +0200)] 
cmake: do not require zlib (#2327)

Followup to #2318 which accidentally made zlib required.

Tested locally by increasing the version in CMakeLists.txt to 1.4.1
(which does not exist yet), and confirming that the build reports that a
suitable version of zlib was not found, while the build continued..

10 months agoFix SOVERSION computation logic in CMake to match libtool's (#1976)
jaimergp [Fri, 13 Sep 2024 19:24:48 +0000 (21:24 +0200)] 
Fix SOVERSION computation logic in CMake to match libtool's (#1976)

Fix SOVERSION computation logic in CMake to match libtool's

Closes #1857

Co-authored-by: isuruf <isuruf@users.noreply.github.com>
Co-authored-by: Timothy Lyanguzov <theta682@gmail.com>
10 months agoarchive_write: validate header before arguments (#2315)
Emil Velikov [Fri, 13 Sep 2024 02:15:34 +0000 (03:15 +0100)] 
archive_write: validate header before arguments (#2315)

Fixes: 575e2eab ("Fix handling a negative bytes_per_block values
(#2206)")

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
10 months agoFix Windows path when writing zip entries (#2309)
yyyy [Thu, 12 Sep 2024 22:05:01 +0000 (06:05 +0800)] 
Fix Windows path when writing zip entries (#2309)

Before writing a zip entry, its' pathname might be modified for two
reasons:

1. Path using Windows path separators will be converted to POSIX style.
2. Path using local encoding will be transcoded if a target charset is
set.

Must make sure these two mechanisms can coexist without overwriting each
other.

10 months agocmake: look for zlib >= 1.2.1 (#2318)
Mostyn Bramley-Moore [Thu, 12 Sep 2024 21:56:34 +0000 (23:56 +0200)] 
cmake: look for zlib >= 1.2.1 (#2318)

zlib 1.2.0 added this improvement for inflate:
"Raw inflate no longer needs an extra dummy byte at end"

libarchive does not feed zlib extra data beyond end of stream, so it
does not work with zlib < 1.2.0.

11 months agoFix ar archive entries having no type (#2290)
наб [Sun, 1 Sep 2024 04:11:23 +0000 (06:11 +0200)] 
Fix ar archive entries having no type (#2290)

Also removes some whitespace damage.

Closes #2241

11 months agotests: reduce zstd long option to 23 (#2305)
Emil Velikov [Sun, 1 Sep 2024 03:28:57 +0000 (04:28 +0100)] 
tests: reduce zstd long option to 23 (#2305)

With 26 and 27, the sub-test is pushing 2G and 4G memory respectively.

There is no particular reason why we need to push for higher limits
here, so let's pick 23 with weights around 0.25G. The test suite overall
is in the 0.25 - 0.5G range and this fits perfectly.

Closes: https://github.com/libarchive/libarchive/issues/2080
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
11 months agozip: Fix test failure (#2304)
yyyy [Sun, 1 Sep 2024 03:26:01 +0000 (11:26 +0800)] 
zip: Fix test failure (#2304)

Fix `test_write_format_zip_stream` failure when `HAVE_ZLIB_H` is not
defined.

If `libz` is present, `zip` archives would be compressed by default,
which requires `zip_version=20`. Otherwise, the archive is not
compressed and only requires `zip_version=10`. I'm building libarchive
on a machine not intended for developing, so basicly there's no optional
dependencies like `libz` available, guess that's why nobody else has
reported this issue.

11 months agoPrefer a != b over !(a == b) (#2303)
Rose Silicon [Sun, 1 Sep 2024 03:03:24 +0000 (23:03 -0400)] 
Prefer a != b over !(a == b) (#2303)

This is not C++ or another language where this may have been necessary,
nor is the condition complex at all; it is only a single equality
comparison.

11 months agocat: squash s/it/is/ typo (#2292)
Emil Velikov [Sat, 31 Aug 2024 09:24:18 +0000 (10:24 +0100)] 
cat: squash s/it/is/ typo (#2292)

Closes: https://github.com/libarchive/libarchive/issues/2128
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
11 months agowindows reader: set tree::current for initial tree walking (#2212)
jet [Wed, 14 Aug 2024 08:39:22 +0000 (17:39 +0900)] 
windows reader: set tree::current for initial tree walking (#2212)

Fixes #2211

11 months agoFix compilation warnings (#2246)
Duncan Horn [Wed, 14 Aug 2024 08:09:01 +0000 (01:09 -0700)] 
Fix compilation warnings (#2246)

Fix warnings I'm hitting, at least with MSVC

11 months agoFix CVE-2024-26256 (#2269)
terrynini [Wed, 14 Aug 2024 08:01:21 +0000 (16:01 +0800)] 
Fix CVE-2024-26256 (#2269)

Opening a manipulated RAR archive could lead to remote code execution

Security: CVE-2024-26256
Co-authored-by: Timothy Lyanguzov <theta682@gmail.com>
11 months agob64encode: Fix typo in error message (#2281)
Tobias Stoeckmann [Mon, 12 Aug 2024 22:22:12 +0000 (00:22 +0200)] 
b64encode: Fix typo in error message (#2281)

If this function fails, log b64encode instead of uu.

13 months agoPax parsing should consistently use the FIRST pathname/linkname (#2264)
Tim Kientzle [Tue, 9 Jul 2024 11:55:23 +0000 (04:55 -0700)] 
Pax parsing should consistently use the FIRST pathname/linkname (#2264)

Pax introduced new headers that appear _before_ the legacy
headers.  So pax archives require earlier properties to
override later ones.

Originally, libarchive handled this by storing the early
headers in memory so that it could do the actual parsing
from back to front.  With this scheme, properties from
early headers were parsed last and simply overwrote
properties from later headers.

PR #2127 reduced memory usage by parsing headers in the
order they appear in the file, which requires later headers
to avoid overwriting already-set properties.  Apparently,
when I made this change, I did not fully consider how charset
translations get handled on Windows, so failed to consistently
recognize when the path or linkname properties were in fact
actually set.  As a result, the legacy path/link values (which have
no charset information) overwrote the pax path/link values (which
are known to be UTF-8), leading to the behavior observed in
#2248.  This PR corrects this bug by adding additional
tests to see if the wide character path or linkname properties
are set.

Related:  This bug was exposed by a new test added in #2228
which does a write/read validation to ensure round-trip filename
handling. This was modified in #2248 to avoid tickling the bug above.
I've reverted the change from #2248 since it's no longer necessary.
I have also added some additional validation to this test to
help ensure that the intermediate archive actually is a pax
format that includes the expected path and linkname properties
in the expected places.

13 months agoFix 'test_pax_filename_encoding_UTF16_win' by explicitly setting hdrcharset (#2248)
Duncan Horn [Sun, 7 Jul 2024 17:52:25 +0000 (10:52 -0700)] 
Fix 'test_pax_filename_encoding_UTF16_win' by explicitly setting hdrcharset (#2248)

It would seem as though #2127 conflicted with my change #2228.

I previously thought that the writer was putting info into the archive
that strings were encoded in UTF-8, but I'm not so sure of that
anymore... In any case, explicitly setting `hdrcharset` on the reader as
well is a reasonable alternative and something we do already.

13 months agoRAR5 reader: clear 'data ready' cache on window buffer reallocs (#2265)
Grzegorz Antoniak [Sun, 7 Jul 2024 17:46:42 +0000 (19:46 +0200)] 
RAR5 reader: clear 'data ready' cache on window buffer reallocs (#2265)

The RAR5 reader is using a small stack of cached pointers to submit the
rendered data to the caller. In malformed files it's possible for this
pointer cache to be desynchronized with the memory buffer those pointers
are pointing to, making libarchive crash on invalid memory access.

OSS-Fuzz Issue: 70024

13 months agoQuickly reject tar entries > 2^60 bytes w/o risking overflow (#2263)
Tim Kientzle [Sat, 6 Jul 2024 07:48:15 +0000 (00:48 -0700)] 
Quickly reject tar entries > 2^60 bytes w/o risking overflow (#2263)

In particular, this ensures that we cannot overflow rounding-up
calculations. Recent tar changes put in a lot of sanity limits on the
sizes of particular kinds of data, but the usual behavior in most cases
was to skip over-large values. The skipping behavior required
rounding-up and accumulating values that could potentially overflow
64-bit integers. This adds some coarser checks that fail more directly
when an entry claims to be more than 1 exbibyte (2^60 bytes), avoiding
any possibility of numeric overflow along these paths.

OSS-Fuzz Issue: 70062

13 months agoFree some strings in the tar reader (#2262)
Tim Kientzle [Sat, 6 Jul 2024 07:47:27 +0000 (00:47 -0700)] 
Free some strings in the tar reader (#2262)

Fix a few cases where strings were initialized (with a heap allocation)
but never properly cleaned up.

OSS-Fuzz Issue: 70056

13 months agoTry to fix some CI config issues on macOS (#2261)
Tim Kientzle [Sat, 6 Jul 2024 07:46:21 +0000 (00:46 -0700)] 
Try to fix some CI config issues on macOS (#2261)

macOS CI is reporting some warnings about unavailable versions of some
utilities. I'll take a stab at fixing those...

13 months agoFix a minor date-parsing bug and fill in missing ISO9660 testing (#2260)
Tim Kientzle [Sat, 6 Jul 2024 07:45:38 +0000 (00:45 -0700)] 
Fix a minor date-parsing bug and fill in missing ISO9660 testing (#2260)

This is somewhat academic, since we don't actually expose any of the
ISO9660 header information that is stored in 17-byte date format, but
inspection revealed an off-by-one error in the parsing here.

This also proved a nice motivation to fill in some verification in our
most basic ISO9660 test case.

13 months agoarchive_entry_perms.3: clarify that you don't need to strdup() [gu]name (#2239)
наб [Fri, 5 Jul 2024 21:36:31 +0000 (23:36 +0200)] 
archive_entry_perms.3: clarify that you don't need to strdup() [gu]name (#2239)

Currently updating archivemount which does
```c
pwd = getpwuid(st.st_uid);
if(pwd)
archive_entry_set_uname(node->entry, strdup(pwd->pw_name));
grp = getgrgid(st.st_gid);
if(grp)
archive_entry_set_gname(node->entry, strdup(grp->gr_name));
```
and I'm assuming the strdups are actually leaks? The manual is silent on
this.

13 months agoFix max path-length metadata writing (#2243)
Sam Bingner [Fri, 5 Jul 2024 19:34:43 +0000 (09:34 -1000)] 
Fix max path-length metadata writing (#2243)

Previous code added `.XXXXXX` to the end of the filename to write the
mac metadata. This is a problem if the filename is at or near the
filesystem max path length. This reuses the same code used by
create_tempdatafork to ensure that the filename is not too long.

13 months agoIgnore out-of-range gid/uid/size/ino and harden AFIO parsing (#2258)
Tim Kientzle [Fri, 5 Jul 2024 10:08:38 +0000 (03:08 -0700)] 
Ignore out-of-range gid/uid/size/ino and harden AFIO parsing (#2258)

The fuzzer constructed an AFIO (CPIO variant) archive that had a
rediculously large ino value, which caused an overflow of a signed
64-bit intermediate.

There are really three issues here:
* The CPIO parser was using a signed int64 as an intermediate type for
parsing numbers in all cases. I've addressed the overflow here by using
a uint64_t in the parser core, but left the resulting values as int64_t.
* The AFIO header parsing had no guards against rediculously large
values; it now rejects an archive when the ino or size fields (which are
allowed to be up to 16 hex digits long) overflow int64_t to produce a
negative value.
* The archive_entry would accept negative values for gid/uid/size/ino.
I've altered those so that these fields treat any negative value as zero
for these fields.

There was one test that actually verified that we could read a field
with size = -1. I've updated that to verify that the resulting size is
zero instead.

OSS-Fuzz Issue: 70019

13 months agoDon't try to read rediculously long names (#2259)
Tim Kientzle [Fri, 5 Jul 2024 10:05:41 +0000 (03:05 -0700)] 
Don't try to read rediculously long names (#2259)

The Rar5 reader would read the name size, then read the name, then check
whether the name size was beyond the maximum size allowed. This can
result in a very large memory allocation to read a name. Instead, check
the name size before trying to read the name in order to avoid excessive
allocation.

OSS-Fuzz Issue: 70017