Check for bad indices in GetReplacementFunc to avoid crashes

This commit is contained in:
Henrik Rydgård 2023-09-23 10:09:55 +02:00
parent 6a8f65b566
commit 8fc01e37d9
3 changed files with 6 additions and 2 deletions

View File

@ -1590,7 +1590,10 @@ std::vector<int> GetReplacementFuncIndexes(u64 hash, int funcSize) {
return emptyResult;
}
const ReplacementTableEntry *GetReplacementFunc(int i) {
const ReplacementTableEntry *GetReplacementFunc(size_t i) {
if (i >= ARRAY_SIZE(entries)) {
return nullptr;
}
return &entries[i];
}

View File

@ -64,7 +64,7 @@ void Replacement_Shutdown();
int GetNumReplacementFuncs();
std::vector<int> GetReplacementFuncIndexes(u64 hash, int funcSize);
const ReplacementTableEntry *GetReplacementFunc(int index);
const ReplacementTableEntry *GetReplacementFunc(size_t index);
void WriteReplaceInstructions(u32 address, u64 hash, int size);
void RestoreReplacedInstruction(u32 address);

View File

@ -563,6 +563,7 @@ void Arm64Jit::Comp_ReplacementFunc(MIPSOpcode op)
const ReplacementTableEntry *entry = GetReplacementFunc(index);
if (!entry) {
ERROR_LOG(HLE, "Invalid replacement op %08x", op.encoding);
// TODO: What should we do here? We're way off in the weeds probably.
return;
}