711a0b48683b71d61caffbd67a90ec8db5412675 is incomplete and missed the case in btrfs_del_ptr(), where multiple items are removed.
> Running "btrfsck --repair /dev/sdd2" crashed as it can happen in > (corrupted) file systems, that slot > nritems. > ... > in that case the count of remaining items (nritems - slot - nr) gets > negative. That is then casted to (unsigned long len), which leads to the > observed crash. Change the tests before the move to handle only the non-corrupted case, were slot + nr < nritems. This does not fix the corruption, but allows btrfsck to finish without crashing. Signed-off-by: Philipp Hahn <h...@univention.de> --- ctree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ctree.c b/ctree.c index 798bde9..201f671 100644 --- a/ctree.c +++ b/ctree.c @@ -2656,7 +2656,7 @@ static noinline int btrfs_del_leaf(struct btrfs_trans_handle *trans, } /* - * delete the item at the leaf level in path. If that empties + * delete 'nr' items at the leaf level in path. If that empties * the leaf, remove it from the tree */ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, @@ -2679,7 +2679,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, nritems = btrfs_header_nritems(leaf); - if (slot + nr != nritems) { + if (slot + nr < nritems) { int data_end = leaf_data_end(root, leaf); memmove_extent_buffer(leaf, btrfs_leaf_data(leaf) + -- 2.11.0 -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html