Skip to content

programs: don't follow symbolic links and junctions in -r on Windows - #4905

Merged
Cyan4973 merged 1 commit into
devfrom
windows-recursive-skip-links
Nov 8, 2026
Merged

Cyan4973 merged 1 commit into
devfrom
windows-recursive-skip-links

Conversation

@Cyan4973

@Cyan4973 Cyan4973 commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

On Windows, zstd -r entered symbolic links and junctions like ordinary directories, although the CLI does not follow links by default (only -f does): UTIL_isLink() always returned 0 there, and the Windows directory walk never checked followLinks. -r could then compress files outside the given directory, and with --rm, delete them (#4853).

This PR treats symbolic links and junctions as links on Windows, both for the names given on the command line and during the recursive walk, and skips them unless -f is used, as on POSIX.

It only matches name surrogate reparse points (IsReparseTagNameSurrogate()), i.e. symbolic links and junctions. Testing FILE_ATTRIBUTE_REPARSE_POINT alone would also skip OneDrive placeholders and deduplicated files, including files named on the command line, since zstdcli.c calls UTIL_isLink() on every input name when links are not followed.

The test comes from #4860 (thanks @Nmd-sketch): it creates a junction (Windows) or a symbolic link (POSIX) pointing outside the tree, and checks that -r --rm leaves the outside file untouched.

Fixes #4853.

The CLI does not follow symbolic links by default (only -f does), but on
Windows UTIL_isLink() always returned 0, and the recursive directory walk
entered symbolic links and junctions like ordinary directories. -r could
then compress, and with --rm delete, files outside the given directory.

Treat name surrogate reparse points, i.e. symbolic links and junctions,
as links, like lstat() does on POSIX. Other reparse points, such as
OneDrive placeholders or deduplicated files, remain regular files and
directories.

Fixes #4853. The test comes from #4860.

Co-authored-by: Nmd-sketch <revusarlic@gmail.com>
@meta-cla meta-cla Bot added the CLA Signed label Nov 8, 2026
@Cyan4973 Cyan4973 self-assigned this Nov 8, 2026
@Cyan4973
Cyan4973 merged commit 4b0e377 into dev Nov 8, 2026
110 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: zstd -r follows directory junctions and symlinks, so -r --rm deletes files outside the given folder

1 participant