]> wimlib.net Git - wimlib/commitdiff
read_metadata_resource(): Simplify check for short resource
authorEric Biggers <ebiggers3@gmail.com>
Tue, 14 Jan 2014 20:49:28 +0000 (14:49 -0600)
committerEric Biggers <ebiggers3@gmail.com>
Tue, 14 Jan 2014 20:50:52 +0000 (14:50 -0600)
src/metadata_resource.c
src/security.c

index f9401d011e71812ae1f30214437bbb2fc6458494..208539da374ee45d52b3597dacd3960e2381e34c 100644 (file)
@@ -73,17 +73,7 @@ read_metadata_resource(WIMStruct *wim, struct wim_image_metadata *imd)
        metadata_lte = imd->metadata_lte;
        metadata_len = metadata_lte->size;
 
        metadata_lte = imd->metadata_lte;
        metadata_len = metadata_lte->size;
 
-       DEBUG("Reading metadata resource.");
-
-       /* There is no way the metadata resource could possibly be less than (8
-        * + WIM_DENTRY_DISK_SIZE) bytes, where the 8 is for security data (with
-        * no security descriptors) and WIM_DENTRY_DISK_SIZE is for the root
-        * entry. */
-       if (metadata_len < 8 + WIM_DENTRY_DISK_SIZE) {
-               ERROR("Expected at least %u bytes for the metadata resource",
-                     8 + WIM_DENTRY_DISK_SIZE);
-               return WIMLIB_ERR_INVALID_METADATA_RESOURCE;
-       }
+       DEBUG("Reading metadata resource (size=%"PRIu64").", metadata_len);
 
        /* Read the metadata resource into memory.  (It may be compressed.) */
        ret = read_full_stream_into_alloc_buf(metadata_lte, &buf);
 
        /* Read the metadata resource into memory.  (It may be compressed.) */
        ret = read_full_stream_into_alloc_buf(metadata_lte, &buf);
@@ -158,19 +148,19 @@ read_metadata_resource(WIMStruct *wim, struct wim_image_metadata *imd)
 
        inode_add_dentry(root, root->d_inode);
 
 
        inode_add_dentry(root, root->d_inode);
 
-       /* Now read the entire directory entry tree into memory. */
+       /* Now read the entire directory entry tree into memory.  */
        DEBUG("Reading dentry tree");
        ret = read_dentry_tree(buf, metadata_len, root);
        if (ret)
                goto out_free_dentry_tree;
 
        DEBUG("Reading dentry tree");
        ret = read_dentry_tree(buf, metadata_len, root);
        if (ret)
                goto out_free_dentry_tree;
 
-       /* Build hash table that maps hard link group IDs to dentry sets */
+       /* Calculate inodes.  */
        ret = dentry_tree_fix_inodes(root, &imd->inode_list);
        if (ret)
                goto out_free_dentry_tree;
 
 
        ret = dentry_tree_fix_inodes(root, &imd->inode_list);
        if (ret)
                goto out_free_dentry_tree;
 
 
-       DEBUG("Running miscellaneous verifications on the dentry tree");
+       DEBUG("Verifying inodes.");
        image_for_each_inode(inode, imd) {
                ret = verify_inode(inode, security_data);
                if (ret)
        image_for_each_inode(inode, imd) {
                ret = verify_inode(inode, security_data);
                if (ret)
index 27c68a4ff9663cb5a7a0995da63bae83a3d916da..9e1c99984180774c221d08b1be550911ff83cfa1 100644 (file)
@@ -52,8 +52,7 @@ new_wim_security_data(void)
  *
  * @metadata_resource: An array that contains the uncompressed metadata
  *                             resource for the WIM image.
  *
  * @metadata_resource: An array that contains the uncompressed metadata
  *                             resource for the WIM image.
- * @metadata_resource_len:     The length of @metadata_resource.  It must be at
- *                             least 8 bytes.
+ * @metadata_resource_len:     The length of @metadata_resource.
  * @sd_ret:    A pointer to a pointer to a wim_security_data structure that
  *             will be filled in with a pointer to a new wim_security_data
  *             structure containing the security data on success.
  * @sd_ret:    A pointer to a pointer to a wim_security_data structure that
  *             will be filled in with a pointer to a new wim_security_data
  *             structure containing the security data on success.
@@ -78,7 +77,8 @@ read_wim_security_data(const u8 metadata_resource[], size_t metadata_resource_le
        const struct wim_security_data_disk *sd_disk;
        const u8 *p;
 
        const struct wim_security_data_disk *sd_disk;
        const u8 *p;
 
-       wimlib_assert(metadata_resource_len >= 8);
+       if (metadata_resource_len < 8)
+               return WIMLIB_ERR_INVALID_METADATA_RESOURCE;
 
        sd = new_wim_security_data();
        if (!sd)
 
        sd = new_wim_security_data();
        if (!sd)
@@ -165,6 +165,8 @@ out_align_total_length:
                        "%u bytes, but calculated %u bytes",
                        sd->total_length, (unsigned)total_len);
        }
                        "%u bytes, but calculated %u bytes",
                        sd->total_length, (unsigned)total_len);
        }
+       if (sd->total_length > metadata_resource_len)
+               goto out_invalid_sd;
        *sd_ret = sd;
        ret = 0;
        goto out;
        *sd_ret = sd;
        ret = 0;
        goto out;