From 72473369b6c48092718d719a36d6f4337a88c176 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sat, 14 May 2022 15:30:59 +0100 Subject: [PATCH] Account for OOB copyOffsets in CircularBuffer::Read Caused crashes in Pokemon --- app/src/main/cpp/skyline/common/circular_buffer.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/skyline/common/circular_buffer.h b/app/src/main/cpp/skyline/common/circular_buffer.h index 0ddfcc8a..0044e6f2 100644 --- a/app/src/main/cpp/skyline/common/circular_buffer.h +++ b/app/src/main/cpp/skyline/common/circular_buffer.h @@ -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(sizeEnd) * sizeof(Type); std::memcpy(pointer, start, static_cast(sizeEnd) * sizeof(Type)); }