Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "read" to fetch misaligned 64bit values from bundle header #63431

Merged
merged 3 commits into from
Jan 7, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/native/corehost/bundle/file_entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@ file_entry_t file_entry_t::read(reader_t &reader, uint32_t bundle_major_version,
// First read the fixed-sized portion of file-entry
file_entry_fixed_t fixed_data;

fixed_data.offset = *(int64_t*)reader.read_direct(sizeof(int64_t));
fixed_data.size = *(int64_t*)reader.read_direct(sizeof(int64_t));
// NB: the file data is potentially unaligned, thus we use "read" to fetch 64bit values
reader.read(&fixed_data.offset, sizeof(int64_t));
reader.read(&fixed_data.size, sizeof(int64_t));

// compressedSize is present only in v6+ headers
fixed_data.compressedSize = bundle_major_version >= 6 ?
*(int64_t*)reader.read_direct(sizeof(int64_t)) :
0;
fixed_data.compressedSize = 0;
if (bundle_major_version >= 6)
{
reader.read(&fixed_data.compressedSize, sizeof(int64_t));
}

fixed_data.type = *(file_type_t*)reader.read_direct(sizeof(file_type_t));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the size of file_type_t here and how is it guaranteed to be aligned? or do reads of its size not need aligning?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an enum with base uint8_t, defined here:

enum file_type_t : uint8_t


Expand Down