mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2024-12-30 21:51:05 +01:00
a3951dc2d7
On all platforms, this would result in out of bounds accesses when getting the component sizes (which uses stuff from VertexLoader_Position.h/VertexLoader_TextCoord.h/VertexLoader_Normal.h). On platforms other than x64 and ARM64, this would also be out of bounds accesses when getting function pointers for the non-JIT vertex loader (in VertexLoader_Position.cpp etc.). Usually both of these would get data from other entries in the same multi-dimensional array, but the last few entries would be truly out of bounds. This does mean that an out of bounds function pointer can be called on platforms that don't have a JIT vertex loader, but it is limited to invalid component formats with values 5/6/7 due to the size of the bitfield the formats come from, so it seems unlikely that this could be exploited in practice. This issue affects a few games; Def Jam: Fight for New York (https://bugs.dolphin-emu.org/issues/12719) and Fifa Street are known to be affected. I have not done any hardware testing for this PR specifically, though I *think* I previously determined that at least a value of 5 behaves the same as float (4). That's what I implemented in any case. I did previously determine that both Def Jam: Fight for New York and Fifa Street use an invalid normal format, but don't actually have lighting enabled when that normal vector is used, so it doesn't change rendering in practice. The color component format also has two invalid values, but VertexLoader_Color.h/.cpp do check for those invalid ones and return a default value instead of doing an out of bounds access.
71 lines
2.3 KiB
C++
71 lines
2.3 KiB
C++
// Copyright 2008 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#pragma once
|
|
|
|
#include "Common/CommonTypes.h"
|
|
#include "Common/EnumMap.h"
|
|
#include "Common/Inline.h"
|
|
|
|
#include "VideoCommon/CPMemory.h"
|
|
#include "VideoCommon/VertexLoader.h"
|
|
|
|
class VertexLoader_Position
|
|
{
|
|
public:
|
|
static DOLPHIN_FORCE_INLINE u32 GetSize(VertexComponentFormat type, ComponentFormat format,
|
|
CoordComponentCount elements)
|
|
{
|
|
return s_table_size[type][format][elements];
|
|
}
|
|
|
|
static TPipelineFunction GetFunction(VertexComponentFormat type, ComponentFormat format,
|
|
CoordComponentCount elements);
|
|
|
|
private:
|
|
template <typename T, auto last_member>
|
|
using EnumMap = typename Common::EnumMap<T, last_member>;
|
|
|
|
using SizeTable =
|
|
EnumMap<EnumMap<EnumMap<u32, CoordComponentCount::XYZ>, ComponentFormat::InvalidFloat7>,
|
|
VertexComponentFormat::Index16>;
|
|
|
|
static constexpr SizeTable s_table_size = []() consteval
|
|
{
|
|
SizeTable table{};
|
|
|
|
using VCF = VertexComponentFormat;
|
|
using FMT = ComponentFormat;
|
|
|
|
table[VCF::Direct][FMT::UByte] = {2, 3};
|
|
table[VCF::Direct][FMT::Byte] = {2, 3};
|
|
table[VCF::Direct][FMT::UShort] = {4, 6};
|
|
table[VCF::Direct][FMT::Short] = {4, 6};
|
|
table[VCF::Direct][FMT::Float] = {8, 12};
|
|
table[VCF::Direct][FMT::InvalidFloat5] = {8, 12};
|
|
table[VCF::Direct][FMT::InvalidFloat6] = {8, 12};
|
|
table[VCF::Direct][FMT::InvalidFloat7] = {8, 12};
|
|
|
|
table[VCF::Index8][FMT::UByte] = {1, 1};
|
|
table[VCF::Index8][FMT::Byte] = {1, 1};
|
|
table[VCF::Index8][FMT::UShort] = {1, 1};
|
|
table[VCF::Index8][FMT::Short] = {1, 1};
|
|
table[VCF::Index8][FMT::Float] = {1, 1};
|
|
table[VCF::Index8][FMT::InvalidFloat5] = {1, 1};
|
|
table[VCF::Index8][FMT::InvalidFloat6] = {1, 1};
|
|
table[VCF::Index8][FMT::InvalidFloat7] = {1, 1};
|
|
|
|
table[VCF::Index16][FMT::UByte] = {2, 2};
|
|
table[VCF::Index16][FMT::Byte] = {2, 2};
|
|
table[VCF::Index16][FMT::UShort] = {2, 2};
|
|
table[VCF::Index16][FMT::Short] = {2, 2};
|
|
table[VCF::Index16][FMT::Float] = {2, 2};
|
|
table[VCF::Index16][FMT::InvalidFloat5] = {2, 2};
|
|
table[VCF::Index16][FMT::InvalidFloat6] = {2, 2};
|
|
table[VCF::Index16][FMT::InvalidFloat7] = {2, 2};
|
|
|
|
return table;
|
|
}
|
|
();
|
|
};
|