Skip to contentSkip to conversation

libext2fs: clamp block-map punch range end to 2^32 blocks

PATCH Applied Darrick J. Wong 2 participants 2 messages Dec 12, 2013 – Dec 15, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libext2fs: clamp block-map punch range end to 2^32 blocks

In the ^extent case, passing ~0ULL as the 'end' parameter to ext2fs_punch() causes the (end - start + 1) calculation to overflow to zero. Since the old-style mapped block files cannot have more than 2^32 blocks, just clamp it to ~0U.

This fixes a regression in t_quota_2off with the patch "libext2fs: use ext2fs_punch() to truncate quota file" applied.

---
 lib/ext2fs/punch.c |    2 ++
 1 file changed, 2 insertions(+)
lib/ext2fs/punch.c +2 -0
index f138297..9fff704 100644
@@ -435,6 +435,8 @@ extern errcode_t ext2fs_punch(ext2_filsys fs, ext2_ino_t ino,
 
 		if (start > ~0U)
 			return 0;
+		if (end > ~0U)
+			end = ~0U;
 		count = ((end - start + 1) < ~0U) ? (end - start + 1) : ~0U;
 		retval = ext2fs_punch_ind(fs, inode, block_buf, 
 					  (blk_t) start, count);
#1 lore raw
Quoted 9 lines · Darrick J. Wong

In the ^extent case, passing ~0ULL as the 'end' parameter to ext2fs_punch() causes the (end - start + 1) calculation to overflow to zero. Since the old-style mapped block files cannot have more than 2^32 blocks, just clamp it to ~0U.

This fixes a regression in t_quota_2off with the patch "libext2fs: use ext2fs_punch() to truncate quota file" applied.

Thanks, applied.

- Ted