From: Theodore Ts'o Date: Sun, 10 Jul 2011 02:25:52 +0000 (-0400) Subject: libext2fs: fix block iterator when the callback function modifies an extent X-Git-Tag: v1.42-WIP-0916~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d8fae3cf421eb5ebc0cf8726885eb81aff0a5d1f;p=thirdparty%2Fe2fsprogs.git 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" --- diff --git a/lib/ext2fs/block.c b/lib/ext2fs/block.c index 0e4ec7751..95ad31e2b 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++) {