forked from Mirrors/btrfs-progs
Btrfs-progs: sanity check the number of items in a leaf V2
I hit this while working on fsck, I got some weird corruption where the number of items was way higher than what would fit in a leaf, which would make things blow up. This fixes the problem by catching it and returning an error so we gracefully exit instead of segfaulting. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>master
parent
0ba706acd8
commit
850581d48a
6
ctree.c
6
ctree.c
|
@ -638,6 +638,12 @@ int btrfs_check_leaf(struct btrfs_root *root,
|
|||
struct btrfs_disk_key key;
|
||||
u32 nritems = btrfs_header_nritems(buf);
|
||||
|
||||
if (nritems * sizeof(struct btrfs_item) > buf->len) {
|
||||
fprintf(stderr, "invalid number of items %llu\n",
|
||||
(unsigned long long)buf->start);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (btrfs_header_level(buf) != 0) {
|
||||
fprintf(stderr, "leaf is not a leaf %llu\n",
|
||||
(unsigned long long)btrfs_header_bytenr(buf));
|
||||
|
|
Loading…
Reference in New Issue