From eb267129580a9b6eccdb3744be8e40c63a8a670a Mon Sep 17 00:00:00 2001 From: David Sterba Date: Wed, 1 Jul 2015 15:20:23 +0200 Subject: 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 --- ctree.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'ctree.c') diff --git a/ctree.c b/ctree.c index 130c61fa..e6e5689a 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) { -- cgit v1.2.3