Re: [PATCH] btrfs: free-space-tree: reject mismatched extent and bitmap items

From: Zhang Cen

Date: Sun May 10 2026 - 10:38:06 EST


On Sun, May 10, 2026 at 04:11:00PM +0800, Qu Wenruo wrote:
> The later half "key->offset > end - key->objectid" is unsafe and very
> hard to read.
>
> "end - key->objectid" can underflow.
>
> Change it to "key->objectid + key->offset > end" will be easier to read.
>
> Furthermore, "key->offset" should never be zero, thus in that case
> a single "key->objectid + key->offset > end" will be more than enough.
>
> For the key->offset != 0 part, it can be validated inside tree-checker.
>
> Please use unlikely() for every validate_free_space_key() failure.

Thanks for the review.

You're right, the range check should not be written around
end - key->objectid. I'll change the loader-side range check to use
key->objectid + key->offset > end, add unlikely() for the validator
failure paths, and add tree-checker validation for zero-length free-space
extent items, matching the existing zero-length bitmap item check.

Thanks,
Zhang