OSDN Git Service

Check clusters count validity.
authorrelan <relan@users.noreply.github.com>
Tue, 21 Mar 2017 06:56:25 +0000 (09:56 +0300)
committerrelan <relan@users.noreply.github.com>
Tue, 21 Mar 2017 06:57:28 +0000 (09:57 +0300)
Other checks heavily depend on clusters count value.

libexfat/mount.c

index 130b5ef..43c79eb 100644 (file)
@@ -276,11 +276,21 @@ int exfat_mount(struct exfat* ef, const char* spec, const char* options)
        {
                /* this can cause I/O errors later but we don't fail mounting to let
                   user rescue data */
-               exfat_warn("file system is larger than underlying device: "
-                               "%"PRIu64" > %"PRIu64,
-                               le64_to_cpu(ef->sb->sector_count) * SECTOR_SIZE(*ef->sb),
+               exfat_warn("file system in sectors is larger than device: "
+                               "%"PRIu64" * %d > %"PRIu64,
+                               le64_to_cpu(ef->sb->sector_count), SECTOR_SIZE(*ef->sb),
                                exfat_get_size(ef->dev));
        }
+       if ((off_t) le32_to_cpu(ef->sb->cluster_count) * CLUSTER_SIZE(*ef->sb) >
+                       exfat_get_size(ef->dev))
+       {
+               exfat_error("file system in clusters is larger than device: "
+                               "%u * %d > %"PRIu64,
+                               le32_to_cpu(ef->sb->cluster_count), CLUSTER_SIZE(*ef->sb),
+                               exfat_get_size(ef->dev));
+               exfat_free(ef);
+               return -EIO;
+       }
 
        ef->root = malloc(sizeof(struct exfat_node));
        if (ef->root == NULL)