Skip to content
Myr

Skip symlinks targeting ancestors of walker root to prevent resource exhaustion

Before adoption: this commit came in with the history the project adopted, so no landing records it.

When --walker=follow is used, symlinks like Wine's z: -> / cause fzf to traverse the entire root filesystem. fastwalk's built-in loop detection only catches this on the second pass, but a single pass through / already causes severe CPU and memory exhaustion. This fix resolves each symlink-to-directory target to its absolute real path and skips it if it is an ancestor of (or equal to) the walker root. Close #4710

authored by Junegunn Choi · committed by Junegunn Choi · parent 2ae7367 · Browse files · 2 files+37 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+37 added−0 removed

  • other:+37 added−0 removed

2 files+37 added−0 removed

modified:src/reader.go+36 added
272 unmodified lines
273 // Use forward slashes when running a Windows binary under WSL or MSYS274 ToSlash: fastwalk.DefaultToSlash(),275 Sort: fastwalk.SortFilesFirst,276 }277278 // When following symlinks, precompute the absolute real paths of walker279 // roots so we can skip symlinks that point to an ancestor. fastwalk's280 // built-in loop detection (shouldTraverse) catches loops on the second281 // pass, but a single pass through a symlink like z: -> / already282 // traverses the entire root filesystem, causing severe resource283 // exhaustion. Skipping ancestor symlinks prevents this entirely.284 var absRoots []string285 if opts.follow {286 for _, root := range roots {287 if real, err := filepath.EvalSymlinks(root); err == nil {288 if abs, err := filepath.Abs(real); err == nil {289 absRoots = append(absRoots, filepath.Clean(abs))290 }291 }292 }293 }294295 ignoresBase := []string{}296 ignoresFull := []string{}297 ignoresSuffix := []string{}298 sep := string(os.PathSeparator)
25 unmodified lines
324 isDirSymlink := isSymlinkToDir(path, de)325 if isDirSymlink && !opts.follow {326 return filepath.SkipDir327 }328 // Skip symlinks whose target is an ancestor of (or equal to)329 // any walker root. Following such symlinks would traverse a330 // superset of the tree we're already walking.331 if isDirSymlink && len(absRoots) > 0 {332 if target, err := filepath.EvalSymlinks(path); err == nil {333 if abs, err := filepath.Abs(target); err == nil {334 abs = filepath.Clean(abs)335 if abs == string(os.PathSeparator) {336 return filepath.SkipDir337 }338 for _, absRoot := range absRoots {339 if absRoot == abs || strings.HasPrefix(absRoot, abs+string(os.PathSeparator)) {340 return filepath.SkipDir341 }342 }343 }344 }345 }346 isDir := de.IsDir() || isDirSymlink347 if isDir {348 base := filepath.Base(path)349 if !opts.hidden && base[0] == '.' && base != ".." {
64 unmodified lines
modified:CHANGELOG.md+1 added
25 unmodified lines
26 - Improved the cache structure, reducing memory footprint per entry by 86x.27 - With the reduced per-entry cost, the cache now has broader coverage.28- fish: Improved command history (CTRL-R) (#4703) (@bitraid)29- Bug fixes30 - `--walker=follow` no longer follows symlinks whose target is an ancestor of the walker root, avoiding severe resource exhaustion when a symlink points outside the tree (e.g. Wine's `z:` → `/`) (#4710)31 - Fixed AWK tokenizer not treating a new line character as whitespace32 - Fixed `--{accept,with}-nth` removing trailing whitespaces with a non-default `--delimiter`33 - Fixed OSC8 hyperlinks being mangled when the URL contains unicode characters (#4707)34 - Fixed `--with-shell` not handling quoted arguments correctly (#4709)
3207 unmodified lines