diff --git a/lib/ext2fs/punch.c b/lib/ext2fs/punch.c index 25d79532..657cb53d 100644 --- a/lib/ext2fs/punch.c +++ b/lib/ext2fs/punch.c @@ -288,8 +288,12 @@ static errcode_t ext2fs_punch_extent(ext2_filsys fs, ext2_ino_t ino, (unsigned long long) end, (unsigned long long) next); if (start <= extent.e_lblk) { + /* + * Have we iterated past the end of the punch region? + * If so, we can stop. + */ if (end < extent.e_lblk) - goto next_extent; + break; dbg_printf("Case #%d\n", 1); /* Start of deleted region before extent; adjust beginning of extent */ @@ -303,8 +307,13 @@ static errcode_t ext2fs_punch_extent(ext2_filsys fs, ext2_ino_t ino, extent.e_lblk += free_count; extent.e_pblk += free_count; } else if (end >= next-1) { + /* + * Is the punch region beyond this extent? This can + * happen if start is already inside a hole. Try to + * advance to the next extent if this is the case. + */ if (start >= next) - break; + goto next_extent; /* End of deleted region after extent; adjust end of extent */ dbg_printf("Case #%d\n", 2);