Align security data correctly
authorEric Biggers <ebiggers3@gmail.com>
Tue, 28 Aug 2012 05:45:14 +0000 (00:45 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Tue, 28 Aug 2012 05:45:14 +0000 (00:45 -0500)
src/dentry.c
src/dentry.h
src/resource.c
src/security.c

index 6676377859041bdf495692a4442f4507a803f40f..4d3fc6825e41c726e6a3e8d09644d2b49557a89f 100644 (file)
@@ -85,6 +85,12 @@ static u64 __dentry_total_length(const struct dentry *dentry, u64 length)
        return (length + 7) & ~7;
 }
 
+u64 dentry_correct_total_length(const struct dentry *dentry)
+{
+       return __dentry_total_length(dentry,
+                                    dentry_correct_length_unaligned(dentry));
+}
+
 /* Real length of a dentry, including the alternate data stream entries, which
  * are not included in the dentry->length field... */
 u64 dentry_total_length(const struct dentry *dentry)
@@ -341,8 +347,7 @@ void calculate_subdir_offsets(struct dentry *dentry, u64 *subdir_offset_p)
                /* Advance the subdir offset by the amount of space the children
                 * of this dentry take up. */
                do {
-                       *subdir_offset_p += __dentry_total_length(child,
-                                                                 dentry_correct_length(child));
+                       *subdir_offset_p += dentry_correct_total_length(child);
                        child = child->next;
                } while (child != dentry->children);
 
index 5b2aeab957fa6709790934b31d6cf089748105f1..ba100029cc5b08e888a5440073717cea8db09ada 100644 (file)
@@ -303,6 +303,7 @@ extern void dentry_remove_ads(struct dentry *dentry, struct ads_entry *entry);
 extern const char *path_stream_name(const char *path);
 
 extern u64 dentry_total_length(const struct dentry *dentry);
+extern u64 dentry_correct_total_length(const struct dentry *dentry);
 
 extern void stbuf_to_dentry(const struct stat *stbuf, struct dentry *dentry);
 
index 0c7a4cf9b40f3a929ec459188e7239fc96051604..0e55725d921e07679a0ef88bc37c3e6038a7976e 100644 (file)
@@ -1256,7 +1256,8 @@ int write_metadata_resource(WIMStruct *w)
         * - plus 8 bytes for an end-of-directory entry following the root
         *   dentry (shouldn't really be needed, but just in case...)
         */
-       subdir_offset = ((sd->total_length + 7) & ~7) + dentry_total_length(root) + 8;
+       subdir_offset = ((sd->total_length + 7) & ~7) +
+                       dentry_correct_total_length(root) + 8;
 
        /* Calculate the subdirectory offsets for the entire dentry tree. */
        calculate_subdir_offsets(root, &subdir_offset);
index b30ffc6522247421551f0d4e260ec1278c54dded..2e83d0e966199aa44b3a14606ee9e38b781cb9c9 100644 (file)
@@ -168,8 +168,10 @@ u8 *write_security_data(const struct wim_security_data *sd, u8 *p)
        DEBUG("Writing security data (total_length = %"PRIu32", num_entries "
              "= %"PRIu32")", sd->total_length, sd->num_entries);
 
+       u32 aligned_length = (sd->total_length + 7) & ~7;
+
        u8 *orig_p = p;
-       p = put_u32(p, sd->total_length);
+       p = put_u32(p, aligned_length);
        p = put_u32(p, sd->num_entries);
 
        for (u32 i = 0; i < sd->num_entries; i++)
@@ -179,6 +181,7 @@ u8 *write_security_data(const struct wim_security_data *sd, u8 *p)
                p = put_bytes(p, sd->sizes[i], sd->descriptors[i]);
 
        wimlib_assert(p - orig_p == sd->total_length);
+       p = put_zeroes(p, aligned_length - sd->total_length);
 
        DEBUG("Successfully wrote security data.");
        return p;