68 Commits
Author SHA1 Message Date
Duncan Horn f75ed3a205 Fix a number of Windows/clang(-cl) issues 2026-08-05 16:44:08 -07:00
Tobias Stoeckmann 8992885932 Fix typos
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-07-17 08:49:12 +02:00
Tobias Stoeckmann 4558c310de Merge pull request #3167 from stoeckmann/unzip_windows
unzip: Add Windows port
2026-06-27 16:56:53 +02:00
Dag-Erling Smørgrav 355f7cb849 bsdunzip_test: Set umask before asserting permissions
Fixes:		34b3da0013 ("unzip: Add symlink tests")
2026-06-24 18:25:00 +02:00
Reyad Attiyat bf0ce94fec unzip: mark bsdunzip as long-path aware on Windows
Signed-off-by: God-damnit-all <53661808+God-damnit-all@users.noreply.github.com>
2026-06-24 18:02:20 +02:00
Tobias Stoeckmann 37b0b5a502 unzip: Add Windows port
Copy missing functionality from libarchive and cpio.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-24 18:02:15 +02:00
Tobias Stoeckmann 61b7147289 unzip: Improve portability
- Use contrib/untar's system_mkdir for extended portability
- Compile warning function only if it's actually used
- Use %H:%M instead of %R in strftime for extended portability
- Introduce system_unlink to add special directory symlink handling

Copy missing functionality from libarchive and cpio.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-24 17:45:23 +02:00
Kaif Khan e1730385ee unzip: reject bare '..' and trailing '/..' in pathname_is_insecure 2026-06-24 12:00:05 +05:30
Kaif Khan 79fe496410 unzip: add regression test for insecure '..' symlink targets 2026-06-24 12:00:05 +05:30
Tobias Stoeckmann 34b3da0013 unzip: Add symlink tests
Verify that symlink creations and overwriting works, i.e. that dangling
symlinks are properly overwritten.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-23 20:12:26 +02:00
Tobias Stoeckmann a3d38d0272 unzip: Add -u test
Verify that -u does not override files which have a newer timestamp.

This also verifies that creation of timestamps properly works.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-23 20:12:26 +02:00
Tobias Stoeckmann 4f70bf0e7b unzip: Add -f test
Verify that -f does not create new files and also does not override
files which have a newer timestamp.

This also verifies that creation of timestamps properly works.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-23 20:12:23 +02:00
Tobias Stoeckmann 2615ba5cd5 libarchive_fe: Import FreeBSD's fnmatch
If system lacks fnmatch(3), use FreeBSD's fnmatch. It's adjusted for
increased compatibility, i.e. it uses strcoll instead of FreeBSD's
library internals and const char pointers where needed with latest
GNU/Linux toolchains.

FreeBSD source can be obtained here:

https://github.com/freebsd/freebsd-src/blob/dc36d6f9bb1753f3808552f3afd30eda9a7b206a/lib/libc/gen/fnmatch.c

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-22 20:32:23 +02:00
Tobias Stoeckmann ed9f5ad7d2 unzip: Skip another test if zlib unavailable
The input file in test_P_encryption uses deflate, which is only
available if zlib is available. Skip the test if built without zlib.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2026-06-21 21:07:43 +02:00
Dustin L. Howett ac92d07bf2 unzip: reject absolute or traversing symlink targets
This is overly broad, and will reject some well-formed archives which
contain symlinks to trees which exist in the archive; however, this is
the best we can do without some rudimentary path parsing.

Fixes GHSA-q4gj-vh8c-67p8
2026-06-09 11:16:02 -05: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
Dag-Erling Smørgrav b92f14a220 unzip: Remove dead code
Remove an #include controlled by a preprocessor symbol that nothing
defines.  I'm not sure if this has ever been needed, or what for, but
it serves no purpose today.
2026-04-17 18:45:55 +02:00
Tobias Stoeckmann ab956a274e Move la_getline into libarchive_fe
This allows easier reuse of the getline implementation in other tools
like cpio (in upcoming commit).
2026-03-16 09:43:45 +01:00
Dag-Erling Smørgrav 8ee661c8e7 Unbreak CMake build 2026-03-02 18:19:07 +01:00
Nagy Tibor 1a7ce43864 bsdunzip: Fix ISO week year and Gregorian year confusion 2026-02-09 06:39:22 +01:00
AZero13 a55b8e8aec Use #warning, not #warn
#warn is a GNU extension
2025-12-26 15:28:12 -05:00
AZero13 b39f91e5da Use >=, not => 2025-12-16 21:48:45 -05: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
Tim Kientzle 609d8122f1 Merge pull request #2658 from stoeckmann/skip_tests
Skip tests if respective support is missing
2025-06-28 19:14:17 -07:00
Tobias Stoeckmann ac66e0bc42 Skip zlib tests if support is missing
If zlib is not supported, do not run tests to avoid false positives.

Also adjust tests to support latest gzip versions (1.10+) which store
less information for improved reproducibility. The gzip binary is
used as a fallback if zlib is not available.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 17:27:48 +02:00
Tobias Stoeckmann c40a3887ab unzip: Pass test if encryption support is missing
If no encryption support exists, the -P option will always fail.
"Skip" the test by making sure that there really is no encryption
support according to libarchive functions.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-03 17:27:48 +02:00
Tobias Stoeckmann 36bac92cd2 tools: Enforce default handling of SIGCHLD
Ignoring SIGCHLD gets passed to child processes. Doing that has
influence on waitpid, namely that zombie processes won't be
created. This means that a status can never be read.

We can't enforce this in library, but libarchive's tools can be
protected against this by enforcing default handling.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
2025-06-02 23:29:49 +02:00
AZero13 cfc1f3a9da Label error and errorx as __LA_NORETURN
This also prevents clang-tidy from reporting some false bugs.
2025-05-19 13:35:19 -04:00
Graham Percival 1b6009d17b Use explicit casts for some functions (#2480) 2025-04-06 09:26:53 +02:00
Peter Kästle c9bc934e7e 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>
2025-03-10 08:43:04 -07:00
Graham Percival 42565b88b5 Cast (mode_t)mode for POSIX functions (#2476) 2025-01-06 16:44:40 -08:00
Zeun 4ebca5ff83 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
2024-12-27 12:53:13 -08:00
Mostyn Bramley-Moore 8ac45a813e 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.
2024-12-08 18:07:49 -08:00
Julian Uy b5d95321d4 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.
2024-12-06 07:57:27 -08:00
Emil Velikov 6287b99eb7 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>
2024-10-12 20:54:16 -07:00
Sevan Janiyan 3f3b3efec2 Always use our supplied la_queue.h (#2222)
On legacy systems the OS supplied `sys/queue.h` may lack the required
macros, so to avoid having to verify if the version of queue.h is of
use, opt to always to `la_queue.h` which will match expectations.

Allows libarchive to build on legacy Darwin where `STAILQ_FOREACH` would
be missing from `sys/queue.h`.

Resolves #2220
2024-06-10 20:42:13 -07:00
Martin Matuška d517c678b8 unzip: do not use getenv() and setenv() in test_I.c (#2177)
This setenv() call may clobber the memory pointed to by lang.

It is also insufficient, since you don't run in a clean environment, so
LANG may be overridden by an inherited LC_ALL or LC_CTYPE, or by the
user's .profile (remember that system() does not execute the command
directly, but passes it to a shell).

Reported-By: dag-erling (quoting)
2024-05-09 18:00:33 -07:00
Tobias Stoeckmann dd8f50c317 unzip: Unify EOF handling (#2175)
If EOF is encountered while reading the new filename after choosing 'r',
avoid out of boundary access and usage of undefined memory content by
treating it the same way as if the question itself was not answered.
2024-05-10 01:32:09 +02:00
Tim Kientzle 7a6bb5f5ac Rename the test to match the filename, and avoid test failures on cas… (#2166)
…e-insensitive filesystems

Resolves #2164
2024-05-04 12:15:56 -07:00
Tobias Stoeckmann 9a50ce48b6 Fix typos (#2165)
Typos found with codespell.
2024-05-04 10:58:25 -07:00
Martin Matuska 83e8b0ea8c tests: setenv LANG to en_US.UTF-8 in bsdunzip test_I.c 2024-04-30 11:28:09 +02:00
Martin Matuska 91ba8ceacf unzip: explicitly set en_US.UTF-8 locale in test_I.c 2024-04-23 07:45:50 +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
Aaron Lindros 862984a870 Fix encoding detection on platforms with nl_langinfo() (#2030)
libarchive relies on its host program to call setlocale() on platforms
with nl_langinfo() present in order to correctly detect the user
selected locale. This ensures that bsdunzip does so.
2023-12-08 17:50:03 -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
Klaus Holst Jacobsen 543c9d74f2 Including getopt.h if HAVE_GETOPT_OPTRESET is defined (#2007)
On platforms that uses optreset we must also include getopt.h to have it
defined
2023-12-04 08:25:42 -08:00
Alfred Wingate a5aac7c929 unzip: Increment option count after swallowing -- (#2022)
* Option count is used later for the position of the file in the
arguments and otherwise it uses -- as the file.

---------

Signed-off-by: Alfred Wingate <parona@protonmail.com>
2023-11-26 17:29:11 -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
Martin Matuska 5c5a9f2b76 unzip: correctly handle arguments following an -x after zipfile 2023-08-04 00:19:29 +02:00