From: David Sterba Date: Wed, 1 Jul 2015 13:20:23 +0000 (+0200) Subject: btrfs-progs: check for item end outside of leaf X-Git-Tag: upstream/4.16.1~2135 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eb267129580a9b6eccdb3744be8e40c63a8a670a;p=platform%2Fupstream%2Fbtrfs-progs.git btrfs-progs: check for item end outside of leaf Enhance leaf check to verify item ends that looks otherwise fine but would exceed leaf. Same check is done in kernel. Reported-by: Robert Marklund Signed-off-by: David Sterba --- diff --git a/ctree.c b/ctree.c index 130c61f..e6e5689 100644 --- a/ctree.c +++ b/ctree.c @@ -521,6 +521,20 @@ btrfs_check_leaf(struct btrfs_root *root, struct btrfs_disk_key *parent_key, goto fail; } } + + for (i = 0; i < nritems; i++) { + if (btrfs_item_end_nr(buf, i) > BTRFS_LEAF_DATA_SIZE(root)) { + btrfs_item_key(buf, &key, 0); + btrfs_print_key(&key); + fflush(stdout); + ret = BTRFS_TREE_BLOCK_INVALID_OFFSETS; + fprintf(stderr, "slot end outside of leaf %llu > %llu\n", + (unsigned long long)btrfs_item_end_nr(buf, i), + (unsigned long long)BTRFS_LEAF_DATA_SIZE(root)); + goto fail; + } + } + return BTRFS_TREE_BLOCK_CLEAN; fail: if (btrfs_header_owner(buf) == BTRFS_EXTENT_TREE_OBJECTID) {