marschall / memoryfilesystem

An in memory implementation of a JSR-203 file system
284 stars 36 forks source link

EXCECUTE-Permission on folder not checked when accessing file #159

Closed chrhuebner closed 1 month ago

chrhuebner commented 1 month ago

The execute permission on the folder containing the file isn't checked properly.

FileSystem fs = MemoryFileSystemBuilder.newEmpty().addFileAttributeView(PosixFileAttributeView.class).setCaseSensitive(true).build();
final Path path = fs.getPath("/", "sub1", "sub2", "test.txt");
final Path parent = path.getParent();
Files.createDirectories(parent);
Files.write(path, "Hello World".getBytes(), StandardOpenOption.CREATE_NEW);
Files.setPosixFilePermissions(parent, Set.of()); // removes execute permission
final byte[] bytes = Files.readAllBytes(path); // Exception expected
System.out.println(new String(bytes));

When I remove the permission on sub1 it works - the exception is thrown:

...
Files.setPosixFilePermissions(parent.getParent(), Set.of()); // removes execute permission on sub1
...

The check in https://github.com/marschall/memoryfilesystem/blob/9d9f843e041b7c325ccf416c1e035ece95e2055e/src/main/java/com/github/marschall/memoryfilesystem/MemoryFileSystem.java#L808 should also be done if isLast is true. But now for the current directory.

chrhuebner commented 1 month ago

It seems as if the execute permission of parent directories are also not checked when files are deleted.

marschall commented 1 month ago

Thanks for reporting, I'll have a look.

marschall commented 1 month ago

I released 2.8.1 to Maven Central which should fix the issue.