OSDN Git Service

Check that file or directory size does not exceed clusters heap.
authorrelan <relan@users.noreply.github.com>
Mon, 20 Mar 2017 06:04:57 +0000 (09:04 +0300)
committerrelan <relan@users.noreply.github.com>
Tue, 21 Mar 2017 06:46:00 +0000 (09:46 +0300)
libexfat/node.c

index e50bb69..1b96e09 100644 (file)
@@ -209,6 +209,8 @@ static bool check_node(const struct exfat* ef, struct exfat_node* node,
                const struct exfat_entry_meta2* meta2)
 {
        int cluster_size = CLUSTER_SIZE(*ef->sb);
+       uint64_t clusters_heap_size =
+                       (uint64_t) le32_to_cpu(ef->sb->cluster_count) * cluster_size;
        char buffer[EXFAT_UTF8_NAME_BUFFER_MAX];
        bool ret = true;
 
@@ -260,6 +262,15 @@ static bool check_node(const struct exfat* ef, struct exfat_node* node,
                ret = false;
        }
 
+       /* File or directory cannot be larger than clusters heap. */
+       if (node->size > clusters_heap_size)
+       {
+               exfat_get_name(node, buffer);
+               exfat_error("'%s' is larger than clusters heap: %"PRIu64" > %"PRIu64,
+                               buffer, node->size, clusters_heap_size);
+               ret = false;
+       }
+
        /* Empty file or directory must be marked as non-contiguous. */
        if (node->size == 0 && node->is_contiguous)
        {