Skip to content
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
Next Next commit
Use "read" to fetch misaligned 64bit values
  • Loading branch information
VSadov committed Jan 6, 2022
commit c48425e9338b8aadd5f84473949671085e5b6ec0
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