33 Commits
Author SHA1 Message Date
Daksh Mamodiya c31361d089 file(ARCHIVE_EXTRACT): Fix resource leaks on error paths
extract_tar() allocates archive_read, archive_write_disk, and
archive_match handles, but several early-return error paths did not free
them. Most notably, a PATTERNS entry matching nothing leaked all three
handles on every call, which accumulates inside a long-running
configure.

Scope the three handles with std::unique_ptr custom deleters so every
return path releases them automatically.  std::unique_ptr does not
invoke the deleter for a null pointer, and the libarchive *_free
functions are themselves no-ops on null, so no explicit guarding is
required.  archive_read_free()/archive_write_free() implicitly close the
handle if needed, matching the previous behavior.

Fixes: #27872
2026-06-15 11:47:24 -04:00
Brad King 995d842e98 Merge topic 'test-archive-symlink-win'
4229667859 Tests: Extend symlink-related archive tests to cross-platform
19f8fcfd24 Tests/File_Archive: Relax more stderr line matching

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !11941
2026-04-23 09:06:36 -04:00
Tyler Yankee 4229667859 Tests: Extend symlink-related archive tests to cross-platform
Use `cmake -E create_symlink` or `file(CREATE_LINK)` as appropriate
instead of `ln -sf` on UNIX only to extend cases of (a) symlinks inside
archives and (b) archive extraction to a directory symlink to non-UNIX
platforms where either of these modes may be supported.

The latter relies on the NEW behavior of CMP0205 as it uses
`COPY_ON_ERROR` for platforms where directory symlinks aren't
supported.

Issue: #27756
2026-04-22 13:59:20 -04:00
Tyler Yankee 19f8fcfd24 Tests/File_Archive: Relax more stderr line matching
Much the same flavor as commit 6e638ce109 (Tests/File_Archive: Relax
stderr line matching, 2026-04-14, v4.3.2~9^2~1).
2026-04-22 13:46:49 -04:00
Brad King 35f7629b6e Merge topic 'revert-extract-symlink'
4397f89c16 Restore archive extraction between directory symlinks
6e638ce109 Tests/File_Archive: Relax stderr line matching

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: buildbot <buildbot@kitware.com>
Merge-request: !11931
2026-04-15 11:48:03 -04:00
Tyler Yankee 4397f89c16 Restore archive extraction between directory symlinks
Commit 03f19aa4ea (cmSystemTools: Fix path traversal vulnerability in
archive extraction, 2026-01-06, v4.3.0-rc1~179^2) incidentally
introduced the `ARCHIVE_EXTRACT_SECURE_SYMLINKS` flag when extracting
archives, which prevents extraction of objects whose location would be
altered by a symlink on disk. However, this particular behavior change
was never documented or tested alongside the other changes in the
commit (absolute paths and path traversal components).

Divergent behavior of this flag from `libarchive` on Windows and
non-Windows platforms needs further investigation. In particular, on
Windows, archives cannot be extracted through directory symlinks, but
can be extracted through junctions. On Linux, archives *can* still be
extracted through symlinks, and archives containing symlinks can be
extracted as well.

The symlink change breaks compatibility with many common use cases of
existing projects, e.g., when extracting an archive inside a symlinked
build directory. Revert the flag until this issue can be explored in a
future version of CMake.

Fixes: #27752
Reported-by: scivision <scivision@users.noreply.github.com>
2026-04-14 15:57:13 -04:00
Tyler Yankee 6e638ce109 Tests/File_Archive: Relax stderr line matching
"Compression format unsupported" errors of this form can only possibly
come from `file(ARCHIVE_CREATE)`, so we don't need to track the line
number of the called function. Reduce the need to update these numbers
every time the test helper script is updated.
2026-04-14 15:48:36 -04:00
AJIOB 97455c3d7e file: Add ARCHIVE_* options to specify pathname encoding
Issue: #26903
2026-03-24 14:07:21 -04:00
AJIOB 25af9288f9 Tests/RunCMake/File_Archive: Match expected errors more extensibly 2026-03-24 14:06:51 -04:00
Alex Overchenko 21eb53e9eb tar: Add option to specify the encoding of archive pathnames
Use OEM by default for backward compatibility

Fixes: #26903
2026-03-11 08:44:44 +03:00
Leslie P. Polzer 03f19aa4ea cmSystemTools: Fix path traversal vulnerability in archive extraction
Add security flags to libarchive extraction to prevent path traversal
(Zip Slip) and absolute path attacks:

- ARCHIVE_EXTRACT_SECURE_NODOTDOT: Block ".." path components
- ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS: Block absolute paths
- ARCHIVE_EXTRACT_SECURE_SYMLINKS: Block symlinks escaping extract dir

This hardens both `cmake -E tar` and `file(ARCHIVE_EXTRACT)` against
malicious archives that attempt to write files outside the intended
extraction directory.
2026-01-16 08:54:07 -05:00
AJIOB e347176424 file(ARCHIVE_CREATE): Add controls for zip and 7z compression method/level
Fixes: #27463
2025-12-17 14:38:30 -05:00
AJIOB 94ae247d44 cli tar: support different algorithms for zip & 7z
Fixes: #27443
2025-12-11 12:00:31 -05:00
AJIOB d4d2a6a19d cli tar: support compression level
Fixes #27422
2025-12-05 20:00:24 +03:00
Brad King 9149ac3f37 Merge topic 'fix-27420'
4fdfa0db1a file(ARCHIVE_CREATE): support multithreading compression
cbf71b21b2 cli tar: support multithreading compression

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !11460
2025-12-05 09:04:58 -05:00
AJIOB 4fdfa0db1a file(ARCHIVE_CREATE): support multithreading compression
Relates: #27420
2025-12-03 02:45:30 -05:00
AJIOB 5b87a5d53e cli tar: implement LZMA support
Fixes: #27433
2025-12-02 10:44:49 +03:00
Brad King 5c1ec64d20 Merge branch 'test-libarchive-3.8.2' into update-libarchive 2025-11-10 15:11:31 -05:00
Brad King 576117b7eb Tests: Update expected Zstandard magic number for libarchive 3.8.2
libarchive 3.8.2 enabled Zstandard's checksum feature in the zstd write
filter.  Update our tests' expected results accordingly.

Fixes: #27355
Reported-by: Funda Wang <fundawang@yeah.net>
2025-11-10 15:11:10 -05:00
AJIOB 5de7a09e77 Tests/RunCMake: Match dots more precisely, part 3 2025-10-20 14:45:24 -04:00
AJIOB 62b112ee25 Tests/RunCMake: Match CMakeLists.txt file name more precisely 2025-10-16 17:42:12 +03:00
AJIOB 06ccd15457 Tests/RunCMake: Match xxx.cmake file name more precisely 2025-10-16 17:42:12 +03:00
Hanna Rusakovich 638cf8f194 Tests/RunCMake: Match CMakeLists.txt file name more precisely 2025-10-15 09:39:01 -04:00
Brad King f4aa34daa7 Tests/RunCMake: Update cmake_minimum_required versions to 3.10
For policy-specific tests, use the version before the policy was
introduced.  Otherwise, use 3.10 where possible.
2024-10-03 11:52:22 -04:00
Yuri Witte d8a9aabd24 file(ARCHIVE_CREATE): add WORKING_DIRECTORY option
Fixes: #25260
Issue: #21653
2024-09-11 09:52:32 -04:00
Brad King 1edf138506 Tests/RunCMake: Update cmake_minimum_required versions
For policy-specific tests, use the version before the policy was
introduced.  Otherwise, use 3.5 where possible.

Also, remove `cmake_minimum_required()` and `project()` calls from
individual cases where they are handled by `CMakeLists.txt`.
2023-02-11 06:24:22 -05:00
Amir Masoud Abdol ed519b1cba file(ARCHIVE_CREATE): Allow higher compression level for Zstd
This allows the Zstd compression-level to be set between 0-19.  I've
adjusted some of the tests, and error messages to indicates the selected
algorithm, and min/max of its compression-level.

Fixes: #24160
2022-11-16 09:15:01 -05:00
Brad King 74ec6b63c2 cmFileCommand: Report keyword errors via argument parser results 2022-07-22 10:32:24 -04:00
Brad King dfff470d15 file(ARCHIVE*): Add test for keyword arguments with missing values 2022-06-29 17:43:41 -04:00
Asit Dhal 195d14e781 file(ARCHIVE_CREATE): Add option to control compression level
Fixes: #21125
2020-09-21 13:08:11 -04:00
Craig Scott bbcff21f71 file(ARCHIVE*): Collapse FILES and DIRECTORY options
The two options were concatenated internally for both ARCHIVE_CREATE
and ARCHIVE_EXTRACT. The distinction between files and dirs was not
meaningful. Therefore, replace them with PATHS or PATTERNS 
to more accurately describe the way the options are used.

Fixes: #20884
2020-06-30 22:01:35 +10:00
Craig Scott 95159b7dea file(ARCHIVE_CREATE): Rename TYPE option to COMPRESSION
Fixes: #20883
2020-06-27 18:38:28 +10:00
Cristian Adam c7e1198a23 file: Add ARCHIVE_{CREATE|EXTRACT} subcommands
Fixes: #20443
2020-03-16 14:33:27 +01:00