You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Certain "pathological" directory modes do not match the native POSIX behaviors. A directory that has S_IRUSR can be enumerated, but not necessarily searched (i.e. one can list the files within it, but cannot access those files). A directory that has S_IXUSR can be searched, but not necessarily enumerated (i.e. one cannot list the files of a directory, but can read those files as long as the entry names are known).
How To Reproduce
Test cases
importosfrompathlibimportPathimportpytestdef_enumerate_fails():
# Prepd=Path("testdir")
d.mkdir(exist_ok=True)
d.chmod(0o777)
# Set weird mode:d.chmod(0b011_101_101) # -wxr-xr-x# We can add the file, even if the directory is not enumerablefile=d/"file.txt"file.write_text("hey")
# We can search the directory and read files within it:assertfile.read_text() =="hey"# We cannot enumerate the directorywithpytest.raises(PermissionError):
list(d.iterdir())
def_search_fails():
# Prepd=Path("testdir")
d.mkdir(exist_ok=True)
d.chmod(0o777)
file=d/"file.txt"file.write_text("hey")
# Set weird mode:d.chmod(0b110_101_101) # rw-r-xr-x# We cannot create any files in the directory, because that requires# searching itanother_file=Path("file.txt")
another_file.write_text("hey")
withpytest.raises(PermissionError):
os.link(another_file, d/"link.txt")
# We can enumerate the directory:assertos.listdir(d) == ["file.txt"]
# We cannot read files inside of the directory (even if we have read access to the file)withpytest.raises(PermissionError):
file.stat()
withpytest.raises(PermissionError):
file.read_text()
deftest_enumerate_realfs():
_enumerate_fails()
deftest_enumerate_fakefs(fs):
_enumerate_fails()
deftest_search_fails():
_search_fails()
deftest_search_fakefs(fs):
_search_fails()
Your environment
Please run the following in the environment where the problem happened and
paste the output.
For directory searching, it looks to be that get_object_from_normpath is responsible for permission checking at each step in path resolution. It incorrectly checks the read bit of the directory objects in _can_read, but it should be checking the execute bit:
Additionally, at least to the best of my knowledge, the permission fall-through behavior is not part of POSIX i.e. if get_uid() == st_uid, then only the S_IXUSR bit should be considered, and not the group/other bits.
As for directory enumeration, I believe it would require a separate check since it depends on a different set of mode bits.
The text was updated successfully, but these errors were encountered:
It incorrectly checks the read bit of the directory objects in _can_read, but it should be checking the execute bit
Right, that seems to be incorrect.
the permission fall-through behavior is not part of POSIX i.e. if get_uid() == st_uid, then only the S_IXUSR bit should be considered, and not the group/other bits
That's also true, I just checked this for the other issue where it also holds.
I actually forgot that there is already a check for uid and gid, so this looks just like a bug fix instead of a refactoring (which I first thought was needed).
@vector-of-bool - this (and the other issue) shall be fixed now in main. Please try it out, and check if you see any other permission-related problems. I'll wait a bit if anything else comes up before making a new release.
Describe the bug
Certain "pathological" directory modes do not match the native POSIX behaviors. A directory that has
S_IRUSR
can be enumerated, but not necessarily searched (i.e. one can list the files within it, but cannot access those files). A directory that hasS_IXUSR
can be searched, but not necessarily enumerated (i.e. one cannot list the files of a directory, but can read those files as long as the entry names are known).How To Reproduce
Test cases
Your environment
Please run the following in the environment where the problem happened and
paste the output.
For directory searching, it looks to be that
get_object_from_normpath
is responsible for permission checking at each step in path resolution. It incorrectly checks theread
bit of the directory objects in_can_read
, but it should be checking theexecute
bit:Additionally, at least to the best of my knowledge, the permission fall-through behavior is not part of POSIX i.e. if
get_uid() == st_uid
, then only theS_IXUSR
bit should be considered, and not the group/other bits.As for directory enumeration, I believe it would require a separate check since it depends on a different set of mode bits.
The text was updated successfully, but these errors were encountered: