diff --git a/src/xenia/kernel/util/xex2.cc b/src/xenia/kernel/util/xex2.cc index bfdd40a7f..c46687aba 100644 --- a/src/xenia/kernel/util/xex2.cc +++ b/src/xenia/kernel/util/xex2.cc @@ -585,9 +585,17 @@ int xe_xex2_read_image_basic_compressed(const xe_xex2_header_t *header, uncompressed_size += data_size + zero_size; } + // Calculate the total size of the XEX image from its headers. + uint32_t total_size = 0; + for (uint32_t i = 0; i < header->section_count; i++) { + xe_xex2_section_t& section = header->sections[i]; + + total_size += section.info.page_count * section.page_size; + } + // Allocate in-place the XEX memory. uint32_t alloc_result = memory->HeapAlloc( - header->exe_address, uncompressed_size, xe::MEMORY_FLAG_ZERO); + header->exe_address, total_size, xe::MEMORY_FLAG_ZERO); if (!alloc_result) { XELOGE("Unable to allocate XEX memory at %.8X-%.8X.", header->exe_address, uncompressed_size);