6623 Commits

Author SHA1 Message Date
Martin Matuska
8a7a9cc527 Release 3.7.9 v3.7.9 2025-03-30 21:59:43 +02:00
Tim Kientzle
94e8650582 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

(cherry picked from commit 29fd918e1886abacca88864ad3676fa237ff21e2)
2025-03-30 21:59:32 +02:00
Christoph Grüninger
16e87c1403 [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

(cherry picked from commit 3a5a34b8211b68709090fcac71c45d9b5f59f4f2)
2025-03-30 21:17:26 +02:00
Christoph Grüninger
39320ae104 [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.

(cherry picked from commit 4237b476fd4ef4b2b5ebac55811d92e73aeb5257)
2025-03-30 21:16:11 +02:00
ARJANEN Loïc Jean David
554e3d44f6 Fix for the ZIP large file test (#2552)
Making the ZIP large file test use the utility functions too.

(cherry picked from commit 9ad0e27f53b0f29168693b9305ae7dd2021348e2)
2025-03-30 21:16:05 +02:00
Peter Kokot
af51e308b2 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.

(cherry picked from commit 2c2266432f1b0bf7be918f354140a6ba4a87a04c)
2025-03-30 21:15:59 +02:00
Martin Matuska
e31747775b Release 3.7.8 v3.7.8 2025-03-20 10:45:48 +01:00
Martin Matuška
d19b93e190 CI: Update FreeBSD build environments (#2534)
FreeBSD 13.4 -> 13.5
FreeBSD 14.1 -> 14.2

(cherry picked from commit 03e15babd6ea5ad6add33b070bb5ef50f79b052c)
2025-03-20 09:35:56 +01:00
nia
3c882bcdbb Only use S_ISSOCK if available. (#2543)
Needed to build on OpenServer 5 Definitive 2018.

(cherry picked from commit f8a34abfbb284f5d5bdd254e4fec52979453b0fa)
2025-03-20 09:31:44 +01:00
Tobias Stoeckmann
2498456743 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>
(cherry picked from commit a88e09a37069dd6a07d65f6dfee08a8563d79d8c)
2025-03-20 09:31:01 +01:00
ljdarj
52a2cfb81f FILE* seeking support (#2539)
Adding a seeker function to archive_read_open_FILE().

Fixes #437.

(cherry picked from commit 09a2ed4853cd177264076a88c98e525e892a0d0b)
2025-03-20 09:30:14 +01:00
Peter Kästle
8ce2aca6c7 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>
(cherry picked from commit c9bc934e7e91d302e0feca6e713ccc38d6d01532)
2025-03-11 10:33:23 +01:00
Tim Kientzle
50f3f29a7e 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.)

(cherry picked from commit 3512329ba9a06a7360601f195c5013c3161f5e70)
2025-03-11 10:32:40 +01:00
François Degros
baae7a3fa4 Handle ARCHIVE_FILTER_LZOP in archive_read_append_filter (#2519)
Fixes #2513

(cherry picked from commit 21f74252f2fee6db896e3db80baa3c36663ede62)
2025-03-11 10:32:33 +01:00
Graham Percival
91e81431b1 Cast (mode_t)mode for POSIX functions (#2476)
(cherry picked from commit 42565b88b5cc7441239269902a9d1735fd9ca0e2)
2025-03-11 10:32:00 +01:00
Mostyn Bramley-Moore
6ee2292401 Fix another GCC version detection error (#2474)
This is another instance of the same bug that was fixed in #2472.

(cherry picked from commit 743bbe97693f648e05dc428a770fefed5f1a7d3f)
2025-03-11 10:31:51 +01:00
Mostyn Bramley-Moore
789864cfab 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.

(cherry picked from commit 7708713b634eb2f72ffe484b565a5a87f58e8cb3)
2025-03-11 10:31:45 +01:00
Sam James
83721b498d 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
(cherry picked from commit a186d9662b4e3bc2e0f39d3248f9c1244c4346cb)
2025-03-11 10:31:40 +01:00
Silent
da4d942751 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.

(cherry picked from commit 14b8803c40d36fe1f0c8b3bb2846d865e3adcfce)
2025-03-11 10:31:35 +01:00
Graham Percival
7d301761a0 Fix compiler nitpicks (#2470)
(cherry picked from commit 25c3d9afeada3241cd966f65bb6a28ae9b47a832)
2025-03-11 10:31:26 +01:00
Graham Percival
04bc28e85f Fix compiler nitpicks (#2469)
(cherry picked from commit 982747fd66ea69875052ec62598a72d2fa2f9469)
2025-03-11 10:31:21 +01:00
Mostyn Bramley-Moore
98f3486025 Detect endianness at build time for common MSVC targets also (#2466)
This should now cover the most common build targets.

(cherry picked from commit 1427f3431d3479dd0bc72cdbbd082fc9391c3cf3)
2025-03-11 10:30:35 +01:00
Graham Percival
f96a23daa9 Fix compiler nitpicks (#2465)
(cherry picked from commit edcae6c164717df48c59e6c2dc3e2510fa34ad87)
2025-03-11 10:30:27 +01:00
Mostyn Bramley-Moore
53445a6205 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.

(cherry picked from commit 561b6430fd558af6e15b3cbe4258e0b30945b411)
2025-03-11 10:30:18 +01:00
Graham Percival
3971e6dfcf Add more casts for %c, %o, and %x (#2463)
(cherry picked from commit 4ce9c2f4bedfef8e4c5962c4d0f59bc400e2a976)
2025-03-11 10:30:05 +01:00
Graham Percival
9f00890419 Spelling fixes for func, struct, and macros (#2462)
(cherry picked from commit dc5e1405b630258c41e0059fd121fca222d8eabd)
2025-03-11 10:30:00 +01:00
Graham Percival
1be3e0a24d Add more casts for %o (#2461)
(cherry picked from commit a2086b67d88d8d3d2d99d80ada3fcd19eaf76ed4)
2025-03-11 10:29:55 +01:00
Graham Percival
27b490a83d Add straightforward casts for %o and %x (#2458)
(cherry picked from commit 14221c7ba20d50598b56f455a6d613ed186e3510)
2025-03-11 10:29:49 +01:00
Mostyn Bramley-Moore
3601017d68 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.

(cherry picked from commit 28cb5064d8dcd256237a736d7d6cbf7873de6671)
2025-03-11 10:29:43 +01:00
Graham Percival
8124935917 Fix format strings (#2457)
(cherry picked from commit a659a44a8511c9a08b28e8d7953382dde0c2c657)
2025-03-11 10:29:29 +01:00
Graham Percival
e210c51955 Add tar/test/test_list_item (#2454)
(cherry picked from commit b557c1f16165a1d28d45ea0bb045b61017aea5a2)
2025-03-11 10:29:22 +01:00
Tim Kientzle
864eb9d655 Fix the test for NOABSOLUTEPATHS (#2456)
The test inadvertently tried to manipulate the wrong archive at one
point.

(cherry picked from commit 12517fa78dc9c232f95b4fa01af7f19e8ee71ad3)
2025-03-11 10:29:17 +01:00
Stephane Chazelas
562cdbcc20 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>
(cherry picked from commit 4d5106f2b5e48a34ec0e341974737252ed5aae84)
2025-03-11 10:29:11 +01:00
Graham Percival
287b153444 Fix remaining TODOs in test_stdio.c (#2444)
(cherry picked from commit 0acaa2994a6c230fc9d83684c151417c9c1e19d1)
2025-03-11 10:28:35 +01:00
Graham Percival
eec67d0d15 Remove unnecessary semicolons (#2450)
(cherry picked from commit 35da265cc3fc21150e14b3d01bafc57bc82eacdc)
2025-03-11 10:28:28 +01:00
Graham Percival
5c53a66994 Remove unreachable 'break' statements (#2451)
(cherry picked from commit 0d1ac07d3fbe39f26e6cf0ad2b38c1be3b421e64)
2025-03-11 10:28:22 +01:00
Graham Percival
2b7917cff0 Fix CRLF line endings in source files (#2449)
(cherry picked from commit e99c6d69f165a2920123c56a04d58d9420347ef9)
2025-03-11 10:27:31 +01:00
Graham Percival
2d78ed5127 Reject relative path for test refdir (#2445)
(cherry picked from commit af4a3562cd436d8b469404759f780c1ca7fe8f12)
2025-03-11 10:27:00 +01:00
Graham Percival
3e339a097a Fix a few clang nitpicks (#2447)
Fixes warnings found by:
```
-Wformat-non-iso
-Wnewline-eof
-Wmissing-variable-declarations
```

(cherry picked from commit 1f6cdd46255fe2397c05f6701c06c9c600d64e87)
2025-03-11 10:26:56 +01:00
Graham Percival
b9caf9d94f Fix some TODOs in tar/test/test_stdio.c (#2442)
(cherry picked from commit 72bbf9ec25eb7097b624f16397c138442e2f8827)
2025-03-11 10:26:52 +01:00
Mostyn Bramley-Moore
43550e7aea 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.

(cherry picked from commit 819a50a0436531276e388fc97eb0b1b61d2134a3)
2025-03-11 10:26:40 +01:00
Mostyn Bramley-Moore
f8fb116935 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

(cherry picked from commit 6516cd137eb5381b2f91773456c7069ba576034a)
2025-03-11 10:26:16 +01:00
Tim Kientzle
e0362b7f1a Handle truncation in the middle of a GNU long linkname (#2422)
Thanks to gbdngb12 김동건 for reporting this.

Resolves Issue #2415

(cherry picked from commit 82912103214506316bd9990d73f33d743d55f570)
2025-03-11 10:26:08 +01:00
Mostyn Bramley-Moore
4757f1eb25 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
```

(cherry picked from commit 7efa99bdb100cc5f32bb16324ef75920e49deaf4)
2025-03-11 10:26:02 +01:00
Mostyn Bramley-Moore
700b3a09ec 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.

(cherry picked from commit 8ac45a813e78fe6f2f8c40f0219f106a7ff9a28f)
2025-03-11 10:25:58 +01:00
Mostyn Bramley-Moore
e8920dd262 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.

(cherry picked from commit ba76798136062868d2cbe80648ebc6fe2ebfbaed)
2025-03-11 10:25:49 +01:00
Mostyn Bramley-Moore
b6ae700fc3 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.

(cherry picked from commit 29802f6a5e8543e61bac7d9dede42abf21ded5aa)
2025-03-11 10:25:43 +01:00
Mostyn Bramley-Moore
5f7d3c7259 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.

(cherry picked from commit 0bbbe2883ef45b2027ea7395a691a855b1296cd1)
2025-03-11 10:25:38 +01:00
Mostyn Bramley-Moore
baed86a9d4 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.

(cherry picked from commit 9b7540aaf1eddf558aa3f221b0c6c4ad5520dc9b)
2025-03-11 10:25:32 +01:00
Julian Uy
b12fd5f2b3 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

(cherry picked from commit 819c5b01a90e738ced6af237a6ae0d1aff981127)
2025-03-11 10:25:07 +01:00