Repository navigation
programs: don't follow symbolic links and junctions in -r on Windows - #4905
Merged
Merged
Conversation
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>
This was referenced Nov 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Windows,
zstd -rentered symbolic links and junctions like ordinary directories, although the CLI does not follow links by default (only-fdoes):UTIL_isLink()always returned 0 there, and the Windows directory walk never checkedfollowLinks.-rcould 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
-fis used, as on POSIX.It only matches name surrogate reparse points (
IsReparseTagNameSurrogate()), i.e. symbolic links and junctions. TestingFILE_ATTRIBUTE_REPARSE_POINTalone would also skip OneDrive placeholders and deduplicated files, including files named on the command line, sincezstdcli.ccallsUTIL_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 --rmleaves the outside file untouched.Fixes #4853.