From 72e0cb91c890ffe4a6c7df4b79fb02009f61e00b Mon Sep 17 00:00:00 2001 From: relan Date: Sun, 23 Feb 2014 11:23:55 +0000 Subject: [PATCH 1/1] Check device size on mount. --- libexfat/mount.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libexfat/mount.c b/libexfat/mount.c index c161372..70c8af5 100644 --- a/libexfat/mount.c +++ b/libexfat/mount.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -252,6 +253,18 @@ int exfat_mount(struct exfat* ef, const char* spec, const char* options) free(ef->sb); return -EIO; } + if (le64_to_cpu(ef->sb->sector_count) * SECTOR_SIZE(*ef->sb) > + exfat_get_size(ef->dev)) + { + free(ef->zero_cluster); + exfat_error("file system is larger than underlying device: " + "%"PRIu64" > %"PRIu64, + le64_to_cpu(ef->sb->sector_count) * SECTOR_SIZE(*ef->sb), + exfat_get_size(ef->dev)); + exfat_close(ef->dev); + free(ef->sb); + return -EIO; + } ef->root = malloc(sizeof(struct exfat_node)); if (ef->root == NULL) -- 2.11.0