]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: fix off-by-one error in file truncation
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 8 Oct 2013 15:51:23 +0000 (11:51 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Tue, 8 Oct 2013 15:51:26 +0000 (11:51 -0400)
When told to truncate a file, ext2fs_file_set_size2() should start with
the first block past the end of the file.  The current calculation
jumps one more block ahead, with the result that it fails to hack off
the last block.  Adding blocksize-1 and dividing is sufficient to find
the last block.

Reviewed-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
lib/ext2fs/fileio.c

index 059bda2dc47ba517b6b2c194677a01a532e68fc4..02e62634170fa6b1cfc2ac340cfd5f40fb698a36 100644 (file)
@@ -393,10 +393,10 @@ errcode_t ext2fs_file_set_size2(ext2_file_t file, ext2_off64_t size)
        EXT2_CHECK_MAGIC(file, EXT2_ET_MAGIC_EXT2_FILE);
 
        truncate_block = ((size + file->fs->blocksize - 1) >>
-                         EXT2_BLOCK_SIZE_BITS(file->fs->super)) + 1;
+                         EXT2_BLOCK_SIZE_BITS(file->fs->super));
        old_size = EXT2_I_SIZE(&file->inode);
        old_truncate = ((old_size + file->fs->blocksize - 1) >>
-                     EXT2_BLOCK_SIZE_BITS(file->fs->super)) + 1;
+                     EXT2_BLOCK_SIZE_BITS(file->fs->super));
 
        /* If we're writing a large file, set the large_file flag */
        if (LINUX_S_ISREG(file->inode.i_mode) &&