Commit Graph

20 Commits

Author SHA1 Message Date
Brad King
edb85664e2 Merge topic 'file-archive-create-patterns-exclude'
9800bd2098 file(ARCHIVE_CREATE): Add PATTERNS_EXCLUDE option

Acked-by: Kitware Robot <kwrobot@kitware.com>
Tested-by: buildbot <buildbot@kitware.com>
Merge-request: !12179
2026-06-18 11:13:03 -04:00
Brad King
6e71816f9e Merge topic 'extract-tar-resource-leak-path'
c31361d089 file(ARCHIVE_EXTRACT): Fix resource leaks on error paths

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !12174
2026-06-16 10:21:52 -04:00
Daksh Mamodiya
9800bd2098 file(ARCHIVE_CREATE): Add PATTERNS_EXCLUDE option
Exclude files and directories matching the given patterns while creating
an archive, using libarchive's matcher for parity with file(ARCHIVE_EXTRACT).

Fixes: #27877.
2026-06-16 15:33:06 +02:00
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
Daksh Mamodiya
531f3b568c file(ARCHIVE_EXTRACT): Add PATTERNS_EXCLUDE option
Omit archive entries matching the given patterns when extracting or
listing. May be combined with PATTERNS; on overlap the exclusion
takes precedence.

Fixes: #27837
2026-06-11 02:04:36 +02: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
AJIOB
97455c3d7e file: Add ARCHIVE_* options to specify pathname encoding
Issue: #26903
2026-03-24 14:07:21 -04: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
Yuri Witte
d8a9aabd24 file(ARCHIVE_CREATE): add WORKING_DIRECTORY option
Fixes: #25260
Issue: #21653
2024-09-11 09:52:32 -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
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