Avoid overlay files overflowing solid heaps (#2387)

This commit is contained in:
Luke Street
2026-09-04 00:33:47 -06:00
committed by GitHub
parent 3efba4ccbd
commit d94135f785
7 changed files with 131 additions and 5 deletions
+13 -4
View File
@@ -12,6 +12,7 @@
#include <limits>
#include <ranges>
#include <string_view>
#include <borealis/log.hpp>
#include "JSystem/JKernel/JKRDvdRipper.h"
#if _WIN32
#include <malloc.h>
@@ -21,6 +22,8 @@ std::atomic<u64> JKRArchive::sArcOverlayGeneration{0};
namespace {
inline constexpr borealis::Log Log{"JKRArchivePri"};
void* alloc_overlay_buffer(u32 size) {
#if _WIN32
return _aligned_malloc(size, alignof(std::max_align_t));
@@ -452,12 +455,18 @@ bool JKRArchive::copyOverlayData(void* buffer, u32 bufferSize, SDIFileEntry* ent
return false;
}
const u32 copySize = overlaySize < bufferSize ? overlaySize : bufferSize;
if (copySize != 0) {
memcpy(buffer, overlayData, copySize);
if (overlaySize > bufferSize) {
std::string path;
getOverlayPath(entry, path);
Log.error("Overlay %s is %u bytes but the game reserved %u\n", path.c_str(), overlaySize,
bufferSize);
return false;
}
if (overlaySize != 0) {
memcpy(buffer, overlayData, overlaySize);
}
if (outSize != nullptr) {
*outSize = copySize;
*outSize = overlaySize;
}
return true;
}