Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileSystemEnumerable has some issues when the item gets deleted during enumeration on Linux #61764

Closed
tmds opened this issue Nov 18, 2021 · 2 comments
Assignees
Milestone

Comments

@tmds
Copy link
Member

tmds commented Nov 18, 2021

On Windows, all information of the FileSystemEntry is retrieved as part of the enumeration syscall.
On Unix, some of the properties are retrieved by making additional stat calls.
This means the Unix implementation needs to handle the case where the item may be deleted after it was reported by the readdir syscall, and before the stat syscall was made to get the additional properties.
For Windows compatibility, the Unix implementation does not throw for errors on the stat call.

These are some issues with the implementation:

  • continueOnError should be used on all calls that retrieve info FileStatus to avoid the exception getting thrown.
  • When the item no longer exists, Attributes should return a value based on the information of the dirent_t. The FileAttributesAreExpected and DirectoryAttributesAreExpected that check for this have a bug which causes them to report a false positive due to performing a stat call when checking to remove FileAttributes.Hidden.
  • The FileStatus gets reused across the enumeration. GetLength is missing a check to ensure the status is initialized that can cause information from the previous entry to leak into the next when the latter can not be initialized.

cc @carlossanlop

@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.IO untriaged New issue has not been triaged by the area owner labels Nov 18, 2021
@ghost
Copy link

ghost commented Nov 18, 2021

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

On Windows, all information of the FileSystemEntry is retrieved as part of the enumeration syscall.
On Unix, some of the properties are retrieved by making additional stat calls.
This means the Unix implementation needs to handle the case where the item may be deleted after it was reported by the readdir syscall, and before the stat syscall was made to get the additional properties.
For Windows compatibility, the Unix implementation does not throw for errors on the stat call.

These are some issues with the implementation:

  • continueOnError should be used on all calls that retrieve info FileStatus to avoid the exception getting thrown.
  • When the item no longer exists, Attributes should return a value based on the information of the dirent_t. The FileAttributesAreExpected and DirectoryAttributesAreExpected that check for this have a bug which causes them to report a false positive due to performing a stat call when checking to remove FileAttributes.Hidden.
  • The FileStatus gets reused across the enumeration. GetLength is missing a check to ensure the status is initialized that can cause information from the previous entry to leak into the next when the latter can not be initialized.

cc @carlossanlop

Author: tmds
Assignees: -
Labels:

area-System.IO, untriaged

Milestone: -

@adamsitnik adamsitnik removed the untriaged New issue has not been triaged by the area owner label Nov 18, 2021
@adamsitnik adamsitnik added this to the 7.0.0 milestone Nov 18, 2021
@adamsitnik
Copy link
Member

Fixed by #60214

@ghost ghost locked as resolved and limited conversation to collaborators Dec 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants