If we can't use ftruncate64(), and have to use ftruncate() instead,
make sure that we don't accidentally truncate the size when we chop it
down to an off_t before calling ftruncate(), lest we severely damage a
filesystem image file.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
#ifdef HAVE_FSTAT64
ftruncate64(fd, new_file_size);
#else
- ftruncate(fd, (off_t) new_file_size);
+ /* Only truncate if new_file_size doesn't overflow off_t */
+ if (((off_t) new_file_size) == new_file_size)
+ ftruncate(fd, (off_t) new_file_size);
#endif
}
if (fd > 0)