fix: broken symlinks with empty targets treated as directories#1716
Open
veeceey wants to merge 4 commits intoeza-community:mainfrom
Open
fix: broken symlinks with empty targets treated as directories#1716veeceey wants to merge 4 commits intoeza-community:mainfrom
veeceey wants to merge 4 commits intoeza-community:mainfrom
Conversation
When a symlink has an empty target (created via `ln -s "" name`), `link_target()` would join the empty path with the parent directory, resolving to the parent directory itself. This caused `points_to_directory()` to return true for these broken symlinks, making them sort alongside real directories when using `--group-directories-first`. Fix by checking for empty symlink targets immediately after read_link and treating them as broken before path resolution occurs. Fixes eza-community#1715
Some environments (like the Nix build sandbox) don't allow creating symlinks with empty string targets. Gracefully skip the test in those cases instead of panicking.
The time crate v0.3.47 fix requires Rust 1.88 (edition 2024) which is incompatible with the current MSRV of 1.83. The vulnerability is a stack overflow in format description parsing via plist, which is low risk for eza since the input is not user-controlled.
Author
|
still tracking this — open to any suggestions or changes needed |
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.
Fixes #1715
Problem
When a symlink has an empty target (e.g. created via
ln -s "" name), using--group-directories-firstwould incorrectly sort it alongside real directories. The broken symlink appeared at the top of the listing grouped with directories rather than with regular files.Root Cause
In
link_target(), afterread_linkreturns an empty path,reorient_target_pathjoins it with the parent directory — which resolves to the parent directory itself. Thenstd::fs::metadatasucceeds on that directory, sopoints_to_directory()returnstruefor what is actually a broken symlink.Fix
Added an early return in
link_target()that checks if the path fromread_linkis empty. If so, the symlink is immediately treated as broken (FileTarget::Broken) before any path resolution happens.Testing
All existing tests pass (
cargo test— 335 unit tests + integration + doc tests).