From b6fa6d370a09247a608e6a46a3d9e761d10a8a39 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Tue, 28 Aug 2012 00:45:14 -0500 Subject: [PATCH] Align security data correctly --- src/dentry.c | 9 +++++++-- src/dentry.h | 1 + src/resource.c | 3 ++- src/security.c | 5 ++++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/dentry.c b/src/dentry.c index 66763778..4d3fc682 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -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); diff --git a/src/dentry.h b/src/dentry.h index 5b2aeab9..ba100029 100644 --- a/src/dentry.h +++ b/src/dentry.h @@ -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); diff --git a/src/resource.c b/src/resource.c index 0c7a4cf9..0e55725d 100644 --- a/src/resource.c +++ b/src/resource.c @@ -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); diff --git a/src/security.c b/src/security.c index b30ffc65..2e83d0e9 100644 --- a/src/security.c +++ b/src/security.c @@ -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; -- 2.43.0