Account for OOB copyOffsets in CircularBuffer::Read

Caused crashes in Pokemon
This commit is contained in:
Billy Laws 2022-05-14 15:30:59 +01:00
parent 0a3cf25823
commit 72473369b6

View File

@ -48,7 +48,7 @@ namespace skyline {
size = sizeBegin + sizeEnd;
}
if (copyFunction && copyOffset) {
if (copyFunction && (copyOffset != 0 && copyOffset < sizeEnd)) {
auto sourceEnd{start + ((copyOffset != -1) ? copyOffset : sizeEnd)};
for (auto source{start}, destination{pointer}; source < sourceEnd; source++, destination++)
@ -59,6 +59,8 @@ namespace skyline {
copyOffset -= sizeEnd;
}
} else {
if (copyOffset)
copyOffset -= static_cast<size_t>(sizeEnd) * sizeof(Type);
std::memcpy(pointer, start, static_cast<size_t>(sizeEnd) * sizeof(Type));
}