yuzu-emu
/
yuzu
Archived
1
0
Fork 0

maxwell_3d: fix out of bounds array access in size estimation

This commit is contained in:
Liam 2023-04-19 23:25:00 -04:00
parent 0cfeb2e8d7
commit eb7c2314f6
1 changed files with 6 additions and 4 deletions

View File

@ -4,6 +4,7 @@
#include <cstring> #include <cstring>
#include <optional> #include <optional>
#include "common/assert.h" #include "common/assert.h"
#include "common/bit_util.h"
#include "common/scope_exit.h" #include "common/scope_exit.h"
#include "common/settings.h" #include "common/settings.h"
#include "core/core.h" #include "core/core.h"
@ -259,12 +260,13 @@ u32 Maxwell3D::GetMaxCurrentVertices() {
size_t Maxwell3D::EstimateIndexBufferSize() { size_t Maxwell3D::EstimateIndexBufferSize() {
GPUVAddr start_address = regs.index_buffer.StartAddress(); GPUVAddr start_address = regs.index_buffer.StartAddress();
GPUVAddr end_address = regs.index_buffer.EndAddress(); GPUVAddr end_address = regs.index_buffer.EndAddress();
static constexpr std::array<size_t, 4> max_sizes = { static constexpr std::array<size_t, 3> max_sizes = {std::numeric_limits<u8>::max(),
std::numeric_limits<u8>::max(), std::numeric_limits<u16>::max(), std::numeric_limits<u16>::max(),
std::numeric_limits<u32>::max(), std::numeric_limits<u32>::max()}; std::numeric_limits<u32>::max()};
const size_t byte_size = regs.index_buffer.FormatSizeInBytes(); const size_t byte_size = regs.index_buffer.FormatSizeInBytes();
const size_t log2_byte_size = Common::Log2Ceil64(byte_size);
return std::min<size_t>( return std::min<size_t>(
memory_manager.GetMemoryLayoutSize(start_address, byte_size * max_sizes[byte_size]) / memory_manager.GetMemoryLayoutSize(start_address, byte_size * max_sizes[log2_byte_size]) /
byte_size, byte_size,
static_cast<size_t>(end_address - start_address)); static_cast<size_t>(end_address - start_address));
} }