From 98dca6c552d73cc39a3cb9d16947b2df5c55ef21 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Mon, 21 Jan 2008 13:43:18 -0500 Subject: [PATCH] resize2fs: Add sanity check for off_t overflow before truncating 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" --- resize/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/resize/main.c b/resize/main.c index 7db4ebc..b3f80f7 100644 --- a/resize/main.c +++ b/resize/main.c @@ -416,7 +416,9 @@ int main (int argc, char ** argv) #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) -- 1.8.3.1