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

File that doesn't exist being returned by ReadDir() #18

Open
racingmars opened this issue Sep 9, 2024 · 1 comment
Open

File that doesn't exist being returned by ReadDir() #18

racingmars opened this issue Sep 9, 2024 · 1 comment
Assignees

Comments

@racingmars
Copy link

On my ext4 filesystem, the ReadDir() function is returning an additional file that doesn't exist anymore. If I list from the operating system, I see:

% ls -al /usr/lib/python3.8 
total 280
drwxr-xr-x   3 root root  12288 Dec 12  2020 ./
drwxr-xr-x 260 root root 258048 Sep  4 17:00 ../
drwxr-xr-x   3 root root  12288 May  6  2023 site-packages/

However, if I call ReadDir("/usr/lib/python3.8") on my open filesystem, I get back two entries in the array:

site-packages
LICENSE.txt

But LICENSE.txt does not exist anymore.

Tracing through the code in the debugger, I can see that the DirectoryEntry2 structure data for this "bad" file is:

{
    Inode: 0,
    RecLen: 4048,
    NameLen: 11,
    Flags: 1,
    Name: "LICENSE.txt",
}

From the ext4 documentation at https://www.kernel.org/doc/html/latest/filesystems/ext4/dynamic.html#linear-classic-directories, it says that a directory entry with inode set to 0 is an unused entry, and that "the last entry in the block has a record length that takes it all the way to the end of the block". This entry appears to be both the "unused inode" and "end-of-block" directory entry, and it is just a fluke that there is old data (the filename/namelen>0) also in the entry.

The fix appears to be to add a new check around line 220 of fs.go in extractDirectoryEntries():

if dirEntry.Inode == 0 {
    // unused directory entry
    continue
}

So that the data in this unused entry doesn't get appended to the dirEntries slice.

@masahiro331 masahiro331 self-assigned this Sep 20, 2024
@masahiro331
Copy link
Owner

Thank you for issues.
Could you fix 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

No branches or pull requests

2 participants