AspectUnk / russh-sftp

SFTP subsystem supported server and client for Russh
Apache License 2.0
64 stars 21 forks source link

Conversion from `FileMode` to `FileType` is incorrect. #36

Closed bspot closed 4 months ago

bspot commented 5 months ago

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.

AspectUnk commented 4 months ago

Thanks!