]> wimlib.net Git - wimlib/blobdiff - src/metadata_resource.c
read_metadata_resource(): Check for named root here
[wimlib] / src / metadata_resource.c
index 041d1f78007bb843631e84f578268fa5f8f88a87..e600f30185b8c01f1423af66b34d9b010de0309c 100644 (file)
@@ -138,8 +138,11 @@ read_metadata_resource(WIMStruct *wim, struct wim_image_metadata *imd)
                          imd->security_data->total_length, root);
 
        if (ret == 0 && root->length == 0) {
-               ERROR("Metadata resource cannot begin with end-of-directory entry!");
-               ret = WIMLIB_ERR_INVALID_DENTRY;
+               WARNING("Metadata resource begins with end-of-directory entry "
+                       "(treating as empty image)");
+               FREE(root);
+               root = NULL;
+               goto out_success;
        }
 
        if (ret) {
@@ -147,6 +150,16 @@ read_metadata_resource(WIMStruct *wim, struct wim_image_metadata *imd)
                goto out_free_security_data;
        }
 
+       if (dentry_has_long_name(root) || dentry_has_short_name(root)) {
+               WARNING("The root directory has a nonempty name (removing it)");
+               FREE(root->file_name);
+               FREE(root->short_name);
+               root->file_name = NULL;
+               root->short_name = NULL;
+               root->file_name_nbytes = 0;
+               root->short_name_nbytes = 0;
+       }
+
        /* This is the root dentry, so set its parent to itself. */
        root->parent = root;
 
@@ -175,6 +188,7 @@ read_metadata_resource(WIMStruct *wim, struct wim_image_metadata *imd)
 
        DEBUG("Done reading image metadata");
 
+out_success:
        imd->root_dentry = root;
        INIT_LIST_HEAD(&imd->unhashed_streams);
        goto out_free_buf;