842 Commits
Author SHA1 Message Date
Dustin L. Howett c63a9d33de Merge pull request #3357 from dnelson-1901/remove-cat
tar: manually combine test files instead of calling cat
2026-08-07 17:58:10 -05:00
subotac ea6bff4f92 Fix empty wide string conversion on Windows 2026-08-06 21:29:20 +03:00
Dan Nelson 93fc73f6dc tar: manually combine test files instead of calling cat
Lets the --ignore-zeros tests run on Windows
2026-08-05 21:20:37 -05:00
Dustin L. Howett d07177dcc3 Merge pull request #3341 from subotac/fix/root-absolute-path-test 2026-08-05 20:26:26 -05:00
Tim Kientzle ca8b5cdfe3 Merge pull request #3345 from PeiweiHu/peiwei_fix
Fix bsdtar’s `@archive` handling by freeing input readers after open failures and applying passphrases to the correct reader object.
2026-08-03 22:16:19 -07:00
Peiwei Hu 337e5fcd0c bsdtar: apply passphrase to appended archive reader
When creating an archive from an @archive argument, configure the
input reader rather than passing the output writer to
archive_read_add_passphrase(). Use the reader for error reporting as
well.
2026-08-03 08:49:58 +08:00
Peiwei Hu 7bd12a903f bsdtar: test passphrase for appended archives
Exercise --passphrase while copying entries from an encrypted
@archive into a new archive, then extract the result and verify the
copied file contents.
2026-08-03 08:49:51 +08:00
Peiwei Hu 0d71fa2ad7 bsdtar: free reader after failed archive open
append_archive_filename() returns after reporting an input archive open
failure so archive creation can continue. Release the input archive
reader before returning to avoid accumulating one reader for every
failed @archive argument.
2026-08-02 23:02:10 +08:00
Tim Kientzle 0c353e1a8f Merge pull request #3343 from dnelson-1901/tar-mode
tar: add --mode option for GNU tar compatibility
2026-08-02 07:34:39 -07:00
Dan Nelson c26faff361 tar: handle --mode when extracting archives also 2026-08-01 15:11:08 -05:00
Dan Nelson e8154e0bfc tar: add --mode option (compatible with gnutar) 2026-08-01 15:11:08 -05:00
Tim Kientzle ea476d962f Merge pull request #3342 from datauwu/bsdcpio-fix-ub
bsdcpio: fix UB signed overflow in time formatting
2026-08-01 08:54:01 -07:00
datauwu 0da2e229b1 bsdtar: fix UB signed overflow in time formatting
Use difftime() instead of changing time_t values by the half-year
range. This avoids signed overflow near the time_t limits without
changing normal output.
2026-08-01 19:48:39 +08:00
subotac abba713e8e Clarify absolute path test extraction roots 2026-07-31 20:26:23 +03:00
subotac 83a023ee30 Fix absolute path test when run as root 2026-07-30 18:40:17 +03:00
Dustin L. Howett 10a7247810 Merge pull request #3294 from datauwu/bsdtar-fix-signed-overflow 2026-07-17 14:06:56 -05:00
datauwu 17fc2be73a bsdtar: remove tar_i64toa()
Format integer values directly at each call site and remove the custom
integer formatter.

This handles the full signed integer range and preserves unsigned byte
counters.
2026-07-18 02:09:50 +08:00
Tobias Stoeckmann c74bb50661 Fix typos
Typos found with codespell.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-17 08:49:17 +02:00
Tobias Stoeckmann 1bcc833a5d Check size arithmetic before memory allocations
Make sure that multiplications do not overflow (or if they overflow,
handle them properly).

This also means that proper data type size_t instead of int is used.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-07 17:57:33 +02:00
datauwu 0053ea743f bsdtar: fix 1-byte OOB read in substitution handling
The -s replacement scanner consumes a backslash and then reads the
escaped byte. If the replacement ends in one literal backslash, the loop
can advance past the terminating NUL and read one byte past the
allocated replacement buffer.

Stop scanning when a backslash is followed by the terminating NUL. The
final literal append then preserves the trailing backslash.
2026-07-07 21:58:54 +08:00
Dustin L. Howett 3c3ec69d44 Merge pull request #3232 from kientzle/kientzle-read-data-into-fd-size-boundary
[Write] Truncate write-to-fd at the declared entry size
2026-07-04 15:08:23 -05:00
Tim Kientzle d2a224f443 Fix the test failure
This was originally developed without the Zip fix from #3230.
Since that's been merged, we need to adjust the expectations here
a bit.
2026-07-03 21:52:27 -07:00
Tim Kientzle e7e408a1a9 [Write] Truncate write-to-fd at the declared entry size
This is the test for....

Update the common archive_read_data_into_fd() to truncate
output to the actual entry size from the most recent
archive_read_header result.

This addresses a hole in handling of certain subtly-malformed archives
that can have more data than declared in the header.  Before this,
bsdtar explicitly truncates the entry data to the actual declared size
when extracting to a file, but did not do so when extracting to
stdout.
2026-07-03 21:41:08 -07:00
Tobias Stoeckmann 47964b3533 Check archive_entry_new2 return value
The memory allocation might fail. Check return value and properly handle
error cases.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-03 22:45:11 +02:00
Reyad Attiyat 6ef83d7a41 tar: mark bsdtar as long-path aware on Windows
bsdtar's -C/--directory option calls SetCurrentDirectoryW(), which is
 limited to MAX_PATH (260) characters unless the process opts in to long
 path support via an application manifest declaring longPathAware.
 Extracting into (or changing into) a directory whose path exceeds 260
 characters fails with "could not chdir".

 Embed a longPathAware application manifest into bsdtar.exe so these
 operations work for long destination paths. Both Windows build systems
 (CMake and the autotools/Makefile.am build) embed it, using different
 mechanisms per toolchain:

   - MinGW/Clang (GNU ld) do not generate an application manifest, so it
     is compiled from a resource script (bsdtar.rc) via windres. This
     manifest replaces the toolchain default, so it also declares the
     asInvoker execution level explicitly.
   - MSVC's linker already embeds a manifest (resource id 1); a duplicate
     RT_MANIFEST resource fails to link (CVT1100). Instead the manifest is
     merged into the linker's default manifest (asInvoker) by adding it to
     the target sources.
2026-06-22 22:37:05 -05:00
Dustin L. Howett 3ccaf85c7c tar: use filesystem-neutral replacement characters in the -s test 2026-06-15 15:08:02 -05:00
Dustin L. Howett 0e4fa9ff0d test: promote the win32-repairing systemf wrapper to all systemf calls 2026-06-15 15:08:02 -05:00
Mostyn Bramley-Moore 490907dd3f tar: Improve -s Invalid replacement string error messages
We can add a bit more context here, to make the error easier to understand.
2026-05-29 00:28:13 +02:00
Tobias Stoeckmann 6f18dd94cd tar: Improve string safety in list_item_verbose
The strcpy and sprintf functions are generally hard to reason about.
While they are safe in this context, I think, it's easy to refactor the
code to avoid them completely.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-16 15:40:13 +02:00
Tim Kientzle 5aa477220e Merge pull request #2927 from stoeckmann/pathmatch_recursion
archive_match: Prevent call stack overflow
2026-05-09 13:48:20 -07:00
Tobias Stoeckmann 6175f49315 Remove const qualifier from modified strings
Strings pointed to by these variables are actually modified. They point
to modifiable data areas (own stack arrays or argv arguments), so the
code does not erroneously modify them. Instead, clarify that they are
modifiable by removing the qualifier.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:21:27 +02:00
Tobias Stoeckmann 2a62d049ea tools: Handle archive_match errors
These functions can return negative values, in which case operation
itself failed. While internal libarchive libraries handle these cases,
the tools don't. Check for negative values in them as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-05-09 12:18:38 +02:00
Tim Kientzle f833d13e6d Fix CMake-based testing 2026-05-06 22:02:15 -07:00
Tim Kientzle 2f5ed45e4c [CMake] Automatically update list.h
`list.h` contains a list of all the tests and is generated
by grepping the test source files for `DEFINE_TEST`.
Previously, it was generated at configure time.
This meant that if you added a new test to an existing
source file, you had to manually reconfigure.

This adds the necessary dependencies so that `list.h`
is regenerated whenever any C test source changes.
This ensures that new tests are always discovered automatically.

Note:  If someone wants to update the autoconf-based
build system to do this, please send a PR.
2026-05-05 20:54:12 -07:00
Tobias Stoeckmann bf7cd8c284 Fix memory leaks in test suites
Release memory so ASAN becomes a viable option for test suites.
2026-04-20 20:12:18 +02:00
Tobias Stoeckmann 53755dc951 Remove periods from error messages
Some error messages previously slipped through. Remove periods from
these messages as well.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-18 14:30:44 +01:00
Tobias Stoeckmann c24fa12410 tools: Remove 'Error : ' prefix in lafe_errc calls
Only a minority of calls to lafe_errc state explicitly that an error
occurred. Remove these few cases for a more unified argument handling.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-16 14:01:56 +01:00
Tobias Stoeckmann 89c5831750 tar: print int64_t uid/gid as long long
On LLP64 systems like Windows 11, overly large uid/gid values would be
truncated.

Same is true on Linux 32 bit.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-03-10 20:10:24 +01:00
Martin Matuška b2d68e2f1a Merge pull request #2813 from AZero13/memcpy
We copy from p, not p + module_len
2025-12-26 10:22:13 +01:00
AZero13 e75e5892fd We copy from p, not p + module_len 2025-12-16 21:41:05 -05:00
AZero13 784b778f3b Fix p == null copy paste error 2025-12-16 21:37:16 -05:00
Martin Matuska cfb02de558 tar: fix off-bounds read resulting from #2787 (3150539ed) 2025-12-09 22:40:42 +01:00
Tim Kientzle 81bc00a549 Merge pull request #2787 from ljdarj/aar
Fix bsdtar zero-length pattern issue.
2025-11-20 21:40:17 -08:00
ARJANEN Loïc Jean David 3150539edb Fix bsdtar zero-length pattern issue.
Uses the sed-like way (and Java-like, and .Net-like, and Javascript-like…) to fix this issue of advancing the string to be processed by one if the match is zero-length.

Fixes libarchive/libarchive#2725 and solves libarchive/libarchive#2438.
2025-11-21 00:44:38 +01:00
Martin Matuška 2caee6a37e Merge pull request #2752 from KlaraSystems/des/safe-writes-umask
Set umask before testing safe writes
2025-11-17 20:26:35 +01:00
AZero13 45a873e998 Bounds check newdir_len
Honestly, this is of little consequence; if old_len is too big the program will crash anyway. However, an error exists just in case.
2025-11-04 19:02:08 -05:00
Dag-Erling Smørgrav 7976476c9f Set umask before testing safe writes
Fixes:		27588eba50 ("Fix replacing a regular file with a dir for ARCHIVE_EXTRACT_SAFE_WRITES")
2025-10-13 21:49:29 +02:00
Tim Kientzle 96f76577d3 Rename err.h to avoid conflict with system header
Depending on header search path ordering, we can easily
confuse libarchive_fe/err.h with the system header.
Rename ours to lafe_err.h to avoid the confusion.
Rename libarchive_fe/err.c to match.
2025-09-13 12:30:03 -07:00
Martin Matuška 52db141ece Merge pull request #2477 from jrtc27/safe-dir-over-reg
Fix replacing a regular file with a dir for ARCHIVE_EXTRACT_SAFE_WRITES
2025-09-10 10:40:44 +02:00
Martin Matuška 6bd863f612 Merge pull request #2710 from meecash/CVE-2025-25724-check_strftime_result
Fix CVE-2025-25724 by checking the result of the strftime
2025-09-10 10:22:58 +02:00