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

Conversion from FileMode to FileType is incorrect. #36

Open
bspot opened this issue Jun 1, 2024 · 0 comments · May be fixed by #37
Open

Conversion from FileMode to FileType is incorrect. #36

bspot opened this issue Jun 1, 2024 · 0 comments · May be fixed by #37

Comments

@bspot
Copy link

bspot commented Jun 1, 2024

The From<FileMode> implementation for FileType uses the bitflags contains function to check the file mode against the FileMode enum members, e.g. mode.contains(FileMode::DIR).

However, the file modes are not flags - their set bits overlap.

As a result, the FileType will be wrong for certain file modes.

Example:

The file is a socket, file mode 0xC000 == 1100000000000000.

The first test is against FileMode::DIR which is 0x4000 == 100000000000000.

Since all set bits in 110000000000000 are also set in 1000000000000000, the check succeeds and the file type is set to FileType::Dir.

@bspot bspot linked a pull request Jun 1, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant