Skip to content

Some filesystem enumeration cases may throw if a symbolic link cycle is detected (link to itself) #52746

Closed

Description

@carlossanlop

Problem

This recent PR introduced fixes for the ReadOnly and Hidden flags. While investigating the implementation of the recently approved symbolic link APIs, @jozkee and I discovered a potential regression for which we did not have any unit tests yet.

Repro steps

  • In Unix, create a folder, then add a symbolic link with a cycle (for example, make it point to itself with ln -s mylink mylink).
  • Enumerate the files with FileSystemEnumerable (making sure the transform predicate returns a string with the path), or call one of the Directory.Enumerate* or Directory.Get* methods that return a list of strings with the paths.

Expected

The enumeration invocation is performed to its completion without throwing.

Actual

The enumeration invocation throws due to encountering a symbolic link with a cycle to itself.

Root cause

Before the PR, the method FileSystemEntry.Initialize, which is a called by FileSystemEnumerator.MoveNext, would silently skip the retrieval of the directory information via stat or lstat:

&& Interop.Sys.Stat(entry.FullPath, out Interop.Sys.FileStatus targetStatus) >= 0)

&& (Interop.Sys.LStat(entry.FullPath, out Interop.Sys.FileStatus linkTargetStatus) >= 0))

Now, we are throwing because we are retrieving the directory information by calling the FileStatysm.IsDirectory method, which internally throws unless otherwise specified:

isDirectory = entry._status.IsDirectory(entry.FullPath);

isDirectory = entry._status.IsDirectory(entry.FullPath);

Fix

Pass the continueOnError: true argument to the IsDirectory calls.

Add unit tests to verify enumeration of directories containing cyclic symbolic links is performed without problems.

Notes

Activity

  1. added this to the 6.0.0 milestone on May 14, 2021
  2. self-assigned this
    on May 14, 2021
  3. ghost added
    untriagedNew issue has not been triaged by the area owner
    on May 14, 2021
  4. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on May 14, 2021
  5. changed the title [-]Some filesystem enumeration cases may throw if a symbolic link cycle is detected[/-] [+]Some filesystem enumeration cases may throw if a symbolic link cycle is detected (link to itself)[/+] on May 20, 2021
  6. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on May 24, 2021
  7. ghost locked as resolved and limited conversation to collaborators on Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.IOuntriagedNew issue has not been triaged by the area owner

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions