From 3efc3a04fc77bf53d5d1ad433144b82b441e0806 Mon Sep 17 00:00:00 2001 From: Eric Sandeen Date: Mon, 2 Oct 2006 09:30:41 -0400 Subject: [PATCH] Check for potential 64-bit overflow in ext2fs_get_device_size() Check for potential overflow for filesystems contained in regular files where the filesystem image size is returned by stat64(). Signed-off-by: Eric Sandeen --- lib/ext2fs/ChangeLog | 6 ++++++ lib/ext2fs/getsize.c | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index e3a9aad..a76d96b 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -1,3 +1,9 @@ +2006-10-02 Eric Sandeen + + * getsize.c (ext2fs_get_device_size): Check to make sure that the + number of blocks doesn't overflow the retblocks return + parameter for regular files using stat64(). + 2006-10-01 Theodore Tso * bitops.h (ext2fs_swab32): Only include ext2fs_swab32() if diff --git a/lib/ext2fs/getsize.c b/lib/ext2fs/getsize.c index a4daa03..30a9c22 100644 --- a/lib/ext2fs/getsize.c +++ b/lib/ext2fs/getsize.c @@ -251,6 +251,11 @@ errcode_t ext2fs_get_device_size(const char *file, int blocksize, if (fstat(fd, &st) == 0) #endif if (S_ISREG(st.st_mode)) { + if ((sizeof(*retblocks) < sizeof(unsigned long long)) && + ((st.st_size / blocksize) > 0xFFFFFFFF)) { + rc = EFBIG; + goto out; + } *retblocks = st.st_size / blocksize; goto out; } -- 1.8.3.1