summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Liam2023-04-19 23:25:00 -0400
committerGravatar Liam2023-04-22 10:35:26 -0400
commiteb7c2314f69b50a171944cbd4ef49f3b765e5b2d (patch)
tree365b5479fc62f8b5731973c2400b0667d3864f85 /src
parentMerge pull request #10057 from liamwhite/its-not-in-the-timeline (diff)
downloadyuzu-eb7c2314f69b50a171944cbd4ef49f3b765e5b2d.tar.gz
yuzu-eb7c2314f69b50a171944cbd4ef49f3b765e5b2d.tar.xz
yuzu-eb7c2314f69b50a171944cbd4ef49f3b765e5b2d.zip
maxwell_3d: fix out of bounds array access in size estimation
Diffstat (limited to 'src')
-rw-r--r--src/video_core/engines/maxwell_3d.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp
index 614d61db4..0932fadc2 100644
--- a/src/video_core/engines/maxwell_3d.cpp
+++ b/src/video_core/engines/maxwell_3d.cpp
@@ -4,6 +4,7 @@
4#include <cstring> 4#include <cstring>
5#include <optional> 5#include <optional>
6#include "common/assert.h" 6#include "common/assert.h"
7#include "common/bit_util.h"
7#include "common/scope_exit.h" 8#include "common/scope_exit.h"
8#include "common/settings.h" 9#include "common/settings.h"
9#include "core/core.h" 10#include "core/core.h"
@@ -259,12 +260,13 @@ u32 Maxwell3D::GetMaxCurrentVertices() {
259size_t Maxwell3D::EstimateIndexBufferSize() { 260size_t Maxwell3D::EstimateIndexBufferSize() {
260 GPUVAddr start_address = regs.index_buffer.StartAddress(); 261 GPUVAddr start_address = regs.index_buffer.StartAddress();
261 GPUVAddr end_address = regs.index_buffer.EndAddress(); 262 GPUVAddr end_address = regs.index_buffer.EndAddress();
262 static constexpr std::array<size_t, 4> max_sizes = { 263 static constexpr std::array<size_t, 3> max_sizes = {std::numeric_limits<u8>::max(),
263 std::numeric_limits<u8>::max(), std::numeric_limits<u16>::max(), 264 std::numeric_limits<u16>::max(),
264 std::numeric_limits<u32>::max(), std::numeric_limits<u32>::max()}; 265 std::numeric_limits<u32>::max()};
265 const size_t byte_size = regs.index_buffer.FormatSizeInBytes(); 266 const size_t byte_size = regs.index_buffer.FormatSizeInBytes();
267 const size_t log2_byte_size = Common::Log2Ceil64(byte_size);
266 return std::min<size_t>( 268 return std::min<size_t>(
267 memory_manager.GetMemoryLayoutSize(start_address, byte_size * max_sizes[byte_size]) / 269 memory_manager.GetMemoryLayoutSize(start_address, byte_size * max_sizes[log2_byte_size]) /
268 byte_size, 270 byte_size,
269 static_cast<size_t>(end_address - start_address)); 271 static_cast<size_t>(end_address - start_address));
270} 272}