Skip to content

ext4: accept non-zero padding bytes in HTree dot/dotdot names - #424

Merged
deitch merged 2 commits into
diskfs:masterfrom
austinvazquez:fix/ext4-htree-dot-padding-bytes
Aug 5, 2026
Merged

ext4: accept non-zero padding bytes in HTree dot/dotdot names#424
deitch merged 2 commits into
diskfs:masterfrom
austinvazquez:fix/ext4-htree-dot-padding-bytes

Conversation

@austinvazquez

Copy link
Copy Markdown
Contributor

parseDirectoryTreeRoot validated the full 4-byte name fields of the "." and ".." directory entries against ['.', 0, 0, 0] / ['.', '.', 0, 0]. The ext4 spec only guarantees that the first name_len bytes are meaningful; the trailing padding bytes may be non-zero and the Linux kernel does not check them.

The strict check broke ReadDir on any HTree-indexed directory whose block happened to contain non-zero padding, e.g. a large pycache directory where bytes 0xa–0xb of the dot entry were observed as '/' (0x2f) and 'a' (0x61).

Fix both checks to compare only the first name_len bytes and remove the now-unused bytes import.

@austinvazquez

austinvazquez commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

For this one, I have a use case which is failing to parse a pycache directory where the bytes 0xa-0xb of the dot entry are '/' and 'a' instead of zero. Reading the on-disk format spec, it certainly seems these should be zero, but even the kernel code (ref) itself only checks the name_len bytes from the field and not reading beyond that.

So perhaps it is ok to only be as strict as the kernel here.

@austinvazquez
austinvazquez marked this pull request as ready for review August 3, 2026 20:57
@austinvazquez

Copy link
Copy Markdown
Contributor Author

A review bot recommended 96d6229 to me. Pushed here as separate commit while I have the hood open.

parseDirectoryTreeRoot validated the full 4-byte name fields of the "."
and ".." directory entries against ['.', 0, 0, 0] / ['.', '.', 0, 0].
The ext4 spec only guarantees that the first name_len bytes are
meaningful; the trailing padding bytes may be non-zero and the Linux
kernel does not check them.

The strict check broke ReadDir on any HTree-indexed directory whose
block happened to contain non-zero padding, e.g. a large __pycache__
directory where bytes 0xa–0xb of the dot entry were observed as '/'
(0x2f) and 'a' (0x61).

Fix both checks to compare only the first name_len bytes and remove the
now-unused bytes import.

Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
@austinvazquez
austinvazquez force-pushed the fix/ext4-htree-dot-padding-bytes branch from 96d6229 to f7331b3 Compare August 3, 2026 21:33

@deitch deitch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one really is funny. But if the kernel is not strict about it, no reason we should be.

@deitch
deitch merged commit d43e027 into diskfs:master Aug 5, 2026
20 checks passed
@deitch

deitch commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

👋 @austinvazquez

You're a Docker and containerd maintainer? We probably have lots of common friends. I will pop you a LinkedIn, we can say hello.

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

Successfully merging this pull request may close these issues.

2 participants