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

Error reading directory entries; extents() using incorrect buffer size #17

Open
racingmars opened this issue Sep 5, 2024 · 0 comments
Assignees

Comments

@racingmars
Copy link

I'm attempting to open the file "/usr/lib/test.txt" on my ext4 filesystem, but receiving an error.

If I do _, err := filesystem.Open("/usr/lib/test.txt"), err is:

open usr/lib/test.txt: failed to read directory: read directory usr/lib/: failed to list directory entries inode(15336348): failed to get directory entries: failed to get extents: failed to get extents: failed to get extents: failed to read leaf node extent: unexpected EOF

Going through the code in the debugger, I believe I know what the problem is.

In the extents() function

func (ext4 *FileSystem) extents(b []byte, extents []Extent) ([]Extent, error) {

I can see that I get to a point where extentHeader.Entries is 50. The extent tree header itself is 12 bytes, and whether internal or leaf nodes of the extent tree, the entries are each 12 bytes. So the header + 50 entries is 612 bytes.

However, when reading the block to pass in to recursive calls to extents(), the buffer is always created to match the SectorSize, 512.

b := make([]byte, SectorSize)

That is why when looping through the 50 entries, extents() is getting an EOF. It creates a byte reader around the 512 bytes it was called with, but it needs to be able to read 612 bytes of data.

I believe the read should be a full block, not just a sector of data. If I change the line b := make([]byte, SectorSize) to b := make([]byte, ext4.sb.GetBlockSize()), I no longer get the error.

@masahiro331 masahiro331 self-assigned this Sep 20, 2024
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