From d8fae3cf421eb5ebc0cf8726885eb81aff0a5d1f Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sat, 9 Jul 2011 22:25:52 -0400 Subject: [PATCH] libext2fs: fix block iterator when the callback function modifies an extent If the callback interator modifies a block in the middle of an extent during a call to the block iterator, causing the extent to be split, ext2_block_iterate3() will end up calling the callback function twice for some number of blocks. Fix this. Signed-off-by: "Theodore Ts'o" --- lib/ext2fs/block.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/ext2fs/block.c b/lib/ext2fs/block.c index 0e4ec77..95ad31e 100644 --- a/lib/ext2fs/block.c +++ b/lib/ext2fs/block.c @@ -453,6 +453,17 @@ errcode_t ext2fs_block_iterate3(ext2_filsys fs, uninit = 0; if (extent.e_flags & EXT2_EXTENT_FLAGS_UNINIT) uninit = EXT2_EXTENT_SET_BMAP_UNINIT; +#if 0 + printf("lblk %llu pblk %llu len %d blockcnt %llu\n", + extent.e_lblk, extent.e_pblk, + extent.e_len, blockcnt); +#endif + if (extent.e_lblk + extent.e_len <= blockcnt) + continue; + if (extent.e_lblk > blockcnt) + blockcnt = extent.e_lblk; + j = blockcnt - extent.e_lblk; + blk += j; for (blockcnt = extent.e_lblk, j = 0; j < extent.e_len; blk++, blockcnt++, j++) { -- 1.8.3.1