mv: symlink exponential walk fix - #14286
Open
mtvb wants to merge 3 commits into
Open
Conversation
sylvestre
reviewed
Aug 30, 2026
|
|
||
| if path.is_dir() { | ||
| // never descend through a symlink. | ||
| let metadata = path.symlink_metadata()?; |
Contributor
There was a problem hiding this comment.
entry.file_type() answers the is-a-directory question straight from readdir's d_type with no syscall on Linux; you only need symlink_metadata() on the non-directory branch for nlink/dev/ino.
|
Binary size comparison: |
Contributor
Author
|
I was unsure about the is_file() branch cause one of my tests failed. My test was faulty, entry.metadata() is fine for files. |
|
GNU testsuite comparison: |
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.
scan_directory_recursive decides recursion with path.is_dir(), which follows symlinks.
Two ln -s .. symlinks branch *2 per level down to the kernel's 40-symlink ELOOP limit, creating 2^40 paths.
Fix: Decide recursion from symlink_metadata() instead of path.is_dir(), so the scanner never descends through a symlink. Since the else branch already called symlink_metadata(), it means no extra syscall - the metadata is now fetched once and used for both the recursion decision and the grouping check.
Fixes #14285