763 Commits

Author SHA1 Message Date
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
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
Graham Percival
f96a23daa9 Fix compiler nitpicks (#2465)
(cherry picked from commit edcae6c164717df48c59e6c2dc3e2510fa34ad87)
2025-03-11 10:30:27 +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
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
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
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
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
Alexander Ziaee
8dc57714e6 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.

(cherry picked from commit 68238f28ee9e051be0c78f91f99b1ad2a4c74a03)
2025-03-11 10:24:50 +01:00
Mostyn Bramley-Moore
c29af25ac9 Rename bsdtar test_extract_tar_absolute_paths source file for consistency
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.

Closes #2400
(cherry picked from commit 87fa7336799e44e1c4b4638056bf780173e3eca4)
2024-11-19 01:15:12 +01:00
Martin Matuška
af119e95ce tests: redirect stdout in one call in test_extract_tar_absolute_paths
This redirects the message "Removing leading '/' from member names"
from stderr to a file in one case.

Closes #2386
(cherry picked from commit 2cea675da23c1fc13eefcd778995d9448a1a7207)
2024-11-19 01:14:56 +01:00
vcoxvco
f88d83b68c 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>
(cherry picked from commit 40ff837717b89e9a5d2c735758f503d124d17b72)
2024-11-19 01:10:21 +01:00
Emil Velikov
a4d7600cec 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>
(cherry picked from commit 6287b99eb78ad4ffada536f75c55902208234425)
2024-10-13 09:38:25 +02:00
Tim Kientzle
08c67e8cb0 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.

(cherry picked from commit 41a2d01453e0245f8b391b082ab412e3fb0299c6)
2024-10-11 08:20:28 +02:00
Mostyn Bramley-Moore
60c7294315 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.

(cherry picked from commit d6dd082adfb93716c31e5093b189fdedb64e5efe)
2024-10-08 10:43:36 +02:00
Dag-Erling Smørgrav
208ea883ef 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.

(cherry picked from commit a90e9d84ec147be2ef6a720955f3b315cb54bca3)
2024-10-08 10:42:40 +02:00
Mostyn Bramley-Moore
b2329b88af 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
```

(cherry picked from commit 6567375f27cc18797062c836f4b0953dfc4b25f3)
2024-10-08 10:42:02 +02:00
Michał Górny
296fe0e35d 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.

(cherry picked from commit fa7e9cd7cbcd41386c30cc75a706805dd4e42716)
2024-09-23 01:38:42 +02:00
Tim Kientzle
dff171decd 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.

(cherry picked from commit 75cdc5947073f346d6926939d94347c8592a913b)
2024-09-23 01:08:30 +02:00
jet
8dbb3b4d54
windows reader: set tree::current for initial tree walking (#2212)
Fixes #2211
2024-08-14 10:39:22 +02:00
Lukas Javorsky
09e7b6b0ac
Fix multiple vulnerabilities identified by SAST (#2256)
I went through ~50 findings of SAST reports and identified a few of them
as true positives. I might still have missed some intended uses or some
magic in the code so please provide feedback if you think some of these
shouldn't be applied and why.

I explained the changes in the separate comments.
2024-07-04 15:51:38 -07:00
Dustin L. Howett
6c467b7753
Fix tar -w on Windows (#2219)
The tar utility reads from stderr to receive user input even when stdin
is a pipe. That is unfortunately unsupported on Windows.

The nearest equivalent is to reopen and read from the console input
handle.

Closes #2215
2024-06-03 20:27:29 -07:00
Tim Kientzle
6ff1cd1e48
Define INT_MAX via #include <limits.h> (#2170)
#2110 added usages of INT_MAX here without adding the necessary header.

Resolves #2162
2024-05-06 20:46:26 -07:00
Tim Kientzle
d9f44c5b44
bsdtar: Fix error handling around strtol() usages (#2110)
The code here had a couple of bad code patterns that seem to have been
copied throughout:
* Checking errno after strtol() -- Standard C doesn't seem to actually
require this, so we shouldn't rely on it
* Casting the result of strtol() directly to `int`. This loses
information prematurely.

Instead, I've added `l` as a temporary of type `long`, use that to hold
the result of `strtol()` until it can be checked. I've also removed the
`errno` tests in favor of checking the end pointer value.

The limit for --strip-components has been raised to 100 000.
2024-04-25 11:39:22 +02:00
Dag-Erling Smørgrav
3efcadf886 zstd: Implement core detection (#2083)
The bsdtar manual page claims that setting zstd:threads to 0 tells zstd
to use as many threads as there are cores in the system, but it actually
disables multi-threading.  Replace 0 with the number of configured
processors.

While here, add a previously missing overflow check.

Co-authored-by: Martin Matuska <martin@matuska.de>
2024-04-23 15:11:40 +02:00
Tobias Stoeckmann
bd974e1b7b
tools: Fix stack overflow with many arguments (#2122)
Supplying a lot of "-" arguments to tools can lead to stack overflow due
to recursive *_getopt function calls.

Proof of Concept:

1. Compile libarchive with Visual Studio 2022
2. Call bsdtar with insane amount of arguments
```
PS> bsdtar.exe ("- "*10000).split(" ")
```
The event log shows that bsdtar.exe failed with `0xc00000fd` (stack
overflow).

If compiled with gcc, this does not happen by default because the code
is internally optimized to use this suggested loop instead. You have to
compile with CFLAGS="-O0" to provoke it with gcc as well.
2024-04-12 22:15:53 -07:00
Ed Maste
6110e9c82d
tar: make error reporting more robust and use correct errno (#2101)
As discussed in #1609.
2024-03-29 15:02:06 -07:00
Dag-Erling Smørgrav
46e93300e5
Set umask before testing --exclude-vcs. (#2082) 2024-03-22 17:36:10 -07:00
Dag-Erling Smørgrav
ac417cce0c
Improved control over frame size in zstd filter. (#2081)
Instead of just `min-frame-size` and `max-frame-size`, we now have four
separate options:

* `min-frame-in` delays the creation of a new frame on flush until the
uncompressed size of the current frame passes a certain threshold.

* `min-frame-out` delays the creation of a new frame on flush until the
compressed size of the current frame passes a certain threshold.

* `max-frame-in` forces the creation of a new frame as soon as possible
after the uncompressed size of the current frame reaches a certain
limit.

* `max-frame-out` forces the creation of a new frame as soon as possible
after the compressed size of the current frame reaches a certain limit.

We now also support `k`, `kB`, `M`, `MB`, `G` and `GB` suffixes for all
four options.

The old options are retained as aliases for the corresponding new
options.
2024-03-22 17:35:29 -07:00
Mark Johnston
d33b939d51
tar: Warn when multiple --option values are specified (#2073)
The accepted way to specify multiple options is to list them all as one
comma-separated parameter. bsdtar would silently ignore all but the last
value, which can be very confusing. Print a warning in this scenario.
2024-03-22 17:33:05 -07:00
Haelwenn Monnier
2039275a70
tar: Add support for --group and --owner (#2054)
Closes: https://github.com/libarchive/libarchive/issues/278
2024-02-08 22:10:17 +01:00
nielash
c857aa5f91
document supported formats for --mac-metadata - see #2041 (#2046)
Doc fix to clarify that `--mac-metadata` is only supported for certain
formats. Hopefully just a short-term fix until support is added for
other formats. (See discussion on #2041)
2023-12-31 19:26:39 -08:00
Mostyn Bramley-Moore
fee65801c4
Add a couple of missing HAVE_PCRE2POSIX_H ifdefs (#2033)
Followup to #2031.
2023-12-11 18:37:29 -08:00
grembo
0f410f8cfb
Add trailing letter b to bsdtar substitute pattern (#2012)
The letter b stands for "from (b)eginning" and specifies that a
substitute expression should be matched from the beginning of the
string, regardless if and where a previous substitute expression
matched.

Example:
Transform filename from B-A to A-B and remove all underscores.

Attempt without option b:

    bsdtar -cft -s '/\(.*\)-\(.*\)/\2-\1/gp' -s "/_//g" ab_c-d_ef
    ab_c-d_ef >> d_ef-ab_c

With option b:

    bsdtar -cft -s '/\(.*\)-\(.*\)/\2-\1/gp' -s "/_//gb" ab_c-d_ef
    ab_c-d_ef >> def-abc
2023-12-10 21:51:13 -08:00
Mostyn Bramley-Moore
d1231a7ea7
Add support for PCRE2 (#2031)
The original PCRE is now end-of-life, and no longer actively maintained.

Implements #2013.
2023-12-09 23:56:53 +01:00
Emil Velikov
d5713db2d4
Minor __LA_NORETURN inspired fixes (#2028)
Earlier MR https://github.com/libarchive/libarchive/pull/2000 forgot to
annotate some functions as __LA_NORETURN. While fixing that I've noticed
that the bsdcat.h header could use some fixes so I've snuck those in.

Kind of make sense to group in one PR, but can split people prefer so.

/cc @AtariDreams fyi

---------

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2023-12-07 19:22:27 -08:00
AtariDreams
616c7dca2b
Replace __LA_DEAD with __LA_NORETURN (#2000)
Also add the MSC_VER version of the macro.
2023-12-04 08:29:29 -08:00
Brooks Davis
7dde502899
VCSid removal (#2017)
The libarchive source tree is littered with `__FBSDID("$FreeBSD.*")` and
'$FreeBSD$' tags left over from extracting it from FreeBSD's Subversion
repo. They never made sense for a git repo as git doesn't expand them
and FreeBSD has now removed `$FreeBSD$` from most local source files so
these stand out.

In addition to `__FBSDID` I've removed `__RCSID` which was used once for
a `$NetBSD$` expansion. There might be more of a case to be made for
preserving this one as a diff-reduction measure, but it seems mostly
pointless.

This builds and tests pass except for
libarchive_test_read_disk_directory_traversals which failed on master as
well.
2023-11-20 17:41:49 -08:00
Luke Rewega
2bb5a1a7dd
tar: respect --strip-components and -s patterns in cru modes on read (#1731) 2023-07-26 08:58:57 +02:00
Dag-Erling Smørgrav
575e7bbf64 Document the new zstd options. 2023-01-09 15:23:53 +01:00
Rosen Penev
0348e24bab
replace time64 functions with normal ones (#1830)
Otherwise there are 32/64-bit pointer conversions going on. In Windows
since MSVC2005, time_t has been 64-bit. MinGW needs a hack to get 64-bit
time_t.

Signed-off-by: Rosen Penev <rosenp@gmail.com>

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2023-01-09 15:15:55 +01:00
Rosen Penev
2e9bcba706
further cleanup _localtime64_s (#1824)
These were missing from 2d329073435d36065ce30bfd29428f6a45e41016

Signed-off-by: Rosen Penev <rosenp@gmail.com>

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2022-12-28 23:05:16 +01:00
TERESH1
0025ae8391
Memory leaks fix for tests (#1829)
Issue #1828
2022-12-27 18:30:21 -08:00
Rosen Penev
2d32907343
cleanup _localtime64_s (#1820)
Signed-off-by: Rosen Penev <rosenp@gmail.com>
2022-12-20 13:48:42 +01:00
Martin Matuska
46627c05ad tests: silence CodeQL warning in tar/test_option_b
Use strncpy() and strncat() instead of strcpy() and strcat()
2022-12-07 16:01:26 +01:00
banjiuqingshan
72cf6b7f06
use regfree to release the memory
use regfree() to release the memory requested by the regular expression.#1804
2022-11-18 09:37:00 +08:00
Sean McBride
8ddc25de87 Fixed issue #1743: Changed sprintf to safer snprintf
Also changed a few vsprintf to vsnprintf.

Most cases were trivial, one private function was changed to take the buffer length, one case required some fancy arithmetic.
2022-06-22 22:23:20 -04:00