diff --git a/src/xenia/cpu/xex_module.cc b/src/xenia/cpu/xex_module.cc index 860b204b5..2753fc698 100644 --- a/src/xenia/cpu/xex_module.cc +++ b/src/xenia/cpu/xex_module.cc @@ -242,13 +242,15 @@ bool XexModule::Load(const std::string& name, const std::string& path, // FIXME: Don't know if 32 is the actual limit, but haven't seen more than 2. const char* string_table[32]; std::memset(string_table, 0, sizeof(string_table)); + size_t max_string_table_index = 0; // Parse the string table - for (size_t i = 0, j = 0; i < opt_import_header->string_table_size; j++) { - assert_true(j < xe::countof(string_table)); + for (size_t i = 0; i < opt_import_header->string_table_size; + ++max_string_table_index) { + assert_true(max_string_table_index < xe::countof(string_table)); const char* str = opt_import_header->string_table + i; - string_table[j] = str; + string_table[max_string_table_index] = str; i += std::strlen(str) + 1; // Padding @@ -260,10 +262,13 @@ bool XexModule::Load(const std::string& name, const std::string& path, auto libraries_ptr = reinterpret_cast(opt_import_header) + opt_import_header->string_table_size + 12; uint32_t library_offset = 0; - for (uint32_t i = 0; i < opt_import_header->library_count; i++) { + uint32_t library_count = opt_import_header->library_count; + for (uint32_t i = 0; i < library_count; i++) { auto library = reinterpret_cast(libraries_ptr + library_offset); - SetupLibraryImports(string_table[library->name_index], library); + size_t library_name_index = library->name_index & 0xFF; + assert_true(library_name_index < max_string_table_index); + SetupLibraryImports(string_table[library_name_index], library); library_offset += library->size; } diff --git a/src/xenia/kernel/user_module.cc b/src/xenia/kernel/user_module.cc index 07894984d..36e11470f 100644 --- a/src/xenia/kernel/user_module.cc +++ b/src/xenia/kernel/user_module.cc @@ -475,10 +475,11 @@ void UserModule::Dump() { reinterpret_cast(opt_import_libraries) + opt_import_libraries->string_table_size + 12; uint32_t library_offset = 0; - for (uint32_t l = 0; l < opt_import_libraries->library_count; l++) { + uint32_t library_count = opt_import_libraries->library_count; + for (uint32_t l = 0; l < library_count; l++) { auto library = reinterpret_cast( libraries + library_offset); - auto name = string_table[library->name_index]; + auto name = string_table[library->name_index & 0xFF]; sb.AppendFormat(" %s - %d imports\n", name, (uint16_t)library->count); diff --git a/src/xenia/kernel/util/xex2.cc b/src/xenia/kernel/util/xex2.cc index dbbea04f3..823ec22f3 100644 --- a/src/xenia/kernel/util/xex2.cc +++ b/src/xenia/kernel/util/xex2.cc @@ -285,7 +285,8 @@ int xe_xex2_read_header(const uint8_t* addr, const size_t length, library->version.value = src_library->version.value; library->min_version.value = src_library->version_min.value; - std::strncpy(library->name, string_table[src_library->name_index], + std::strncpy(library->name, + string_table[src_library->name_index & 0xFF], xe::countof(library->name)); library->record_count = src_library->count;