summaryrefslogtreecommitdiff
path: root/dir-item.c
diff options
context:
space:
mode:
Diffstat (limited to 'dir-item.c')
-rw-r--r--dir-item.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/dir-item.c b/dir-item.c
index 0b7250c9..d64f71e3 100644
--- a/dir-item.c
+++ b/dir-item.c
@@ -263,7 +263,6 @@ int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
struct btrfs_path *path,
struct btrfs_dir_item *di)
{
-
struct extent_buffer *leaf;
u32 sub_item_len;
u32 item_len;
@@ -273,7 +272,15 @@ int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
sub_item_len = sizeof(*di) + btrfs_dir_name_len(leaf, di) +
btrfs_dir_data_len(leaf, di);
item_len = btrfs_item_size_nr(leaf, path->slots[0]);
- if (sub_item_len == item_len) {
+
+ /*
+ * If @sub_item_len is longer than @item_len, then it means the
+ * name_len is just corrupted.
+ * No good idea to know if there is anything we can recover from
+ * the corrupted item.
+ * Just delete the item.
+ */
+ if (sub_item_len >= item_len) {
ret = btrfs_del_item(trans, root, path);
} else {
unsigned long ptr = (unsigned long)di;
@@ -294,12 +301,6 @@ static int verify_dir_item(struct btrfs_root *root,
u16 namelen = BTRFS_NAME_LEN;
u8 type = btrfs_dir_type(leaf, dir_item);
- if (type >= BTRFS_FT_MAX) {
- fprintf(stderr, "invalid dir item type: %d\n",
- (int)type);
- return 1;
- }
-
if (type == BTRFS_FT_XATTR)
namelen = XATTR_NAME_MAX;