kdave / btrfs-progs

Development of userspace BTRFS tools
GNU General Public License v2.0
549 stars 241 forks source link

Error on converting ext4 image with xattrs #60

Open panruochen opened 7 years ago

panruochen commented 7 years ago

This error occurs on some special images only. I get this image by flash a sparse image onto the device and the dump the raw partition back. The image is here: https://github.com/panruochen/bad-ext4-sample/archive/master.zip

I add debug logs and find that the converter tries to copy an inode whose number is 8193. But from dumpe2fs information inode 8193 is free.

Looking into source code, it seems that ext2fs_get_next_inode returns both valid and invalid inode numbers and ext2_copy_inodes does not not check if the inode number is valid or not.

To make the convert work, I add the following patch. Does it make sense? 1.zip

kdave commented 7 years ago

Looking into source code, it seems that ext2fs_get_next_inode returns both valid and invalid inode numbers and ext2_copy_inodes does not not check if the inode number is valid or not.

This looks like the root cause, however I'm not sure about the fix. I've looked to e2fsprogs for some examples and found this gem: https://github.com/tytso/e2fsprogs/blob/master/lib/ext2fs/inode.c#L640 which is probably what you found as well.

Good that you have provided the image to reproduce the problem, that should help.

adam900710 commented 7 years ago

This is somewhat hard to fix in btrfs territory.

What about calling e2fsck before doing the real convert thing?

kdave commented 3 years ago

I'm going through old issues, and had another look at this. e2fsck would find the provided image ok, so that won't help. The proposed patch works, with one minor fix with initialized offset to 0. I still don't understand if it's a complete fix and there's no 1:1 code in e2fsprogs that would help understanding it, but as fsck is ok with that it must be there. I'm now running the convert tests, no problems so far. I think the images created have never created the inode outside of the range.

Current plan is to add the fix to convert and figure out how to create an image to verify it works, the provided one is too big. The e2image is smaller but I can't find a way how to make it back to a fs where at least check works, not to say convert.