fs/ntfs3: Fix attr_insert_range at end of file

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>
This commit is contained in:
Konstantin Komarov 2024-05-30 10:44:17 +03:00
parent 0f9579d9e0
commit 519f38de57
No known key found for this signature in database
GPG Key ID: A9B0331F832407B6

View 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;
}