]> www.infradead.org Git - linux.git/commitdiff
fs/ntfs3: Fix attr_insert_range at end of file
authorKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Thu, 30 May 2024 07:44:17 +0000 (10:44 +0300)
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Wed, 26 Jun 2024 12:48:50 +0000 (15:48 +0300)
If the offset is equal to or greater than the end of
file, an error is returned. For such operations (i.e., inserting
a hole at the end of file), ftruncate(2) should be used.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
fs/ntfs3/attrib.c

index 0d13da5523b1ae2a76f99798ece24d0cdc515f36..68d1c61fe3b5ca6ea1c4fb55a012b0f910555c16 100644 (file)
@@ -2373,8 +2373,13 @@ int attr_insert_range(struct ntfs_inode *ni, u64 vbo, u64 bytes)
                mask = (sbi->cluster_size << attr_b->nres.c_unit) - 1;
        }
 
-       if (vbo > data_size) {
-               /* Insert range after the file size is not allowed. */
+       if (vbo >= data_size) {
+               /*
+                * Insert range after the file size is not allowed.
+                * If the offset is equal to or greater than the end of
+                * file, an error is returned.  For such operations (i.e., inserting
+                * a hole at the end of file), ftruncate(2) should be used.
+                */
                return -EINVAL;
        }