summaryrefslogtreecommitdiff
path: root/Source/UnitTests/VideoCommon
diff options
context:
space:
mode:
authorAdmiral H. Curtiss <pikachu025@gmail.com>2024-04-04 22:10:18 +0200
committerGitHub <noreply@github.com>2024-04-04 22:10:18 +0200
commitad331205d1b3c4efb41981a332c9d6fc86009ce3 (patch)
tree8ae92d26c027eaa38af74f5ba3528f5a7087b10e /Source/UnitTests/VideoCommon
parent4312840a4b8cd52ce1beee3a13ba12afe2b59e53 (diff)
parenta3951dc2d72ebb6f240d592fdbb348137130ce49 (diff)
Merge pull request #12684 from Pokechu22/invalid-vertex-component
Fix out of bounds accesses for invalid vertex component formats
Diffstat (limited to 'Source/UnitTests/VideoCommon')
-rw-r--r--Source/UnitTests/VideoCommon/VertexLoaderTest.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp
index 24f975d8fc..eedbff0304 100644
--- a/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp
+++ b/Source/UnitTests/VideoCommon/VertexLoaderTest.cpp
@@ -121,7 +121,9 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values(VertexComponentFormat::Direct, VertexComponentFormat::Index8,
VertexComponentFormat::Index16),
::testing::Values(ComponentFormat::UByte, ComponentFormat::Byte, ComponentFormat::UShort,
- ComponentFormat::Short, ComponentFormat::Float),
+ ComponentFormat::Short, ComponentFormat::Float,
+ ComponentFormat::InvalidFloat5, ComponentFormat::InvalidFloat6,
+ ComponentFormat::InvalidFloat7),
::testing::Values(CoordComponentCount::XY, CoordComponentCount::XYZ),
::testing::Values(0, 1, 31) // frac
));
@@ -170,10 +172,12 @@ TEST_P(VertexLoaderParamTest, PositionAll)
{
input_size = addr == VertexComponentFormat::Index8 ? 1 : 2;
for (int i = 0; i < count; i++)
+ {
if (addr == VertexComponentFormat::Index8)
Input<u8>(i);
else
Input<u16>(i);
+ }
VertexLoaderManager::cached_arraybases[CPArray::Position] = m_src.GetPointer();
g_main_cp_state.array_strides[CPArray::Position] = elem_count * elem_size;
}
@@ -195,6 +199,9 @@ TEST_P(VertexLoaderParamTest, PositionAll)
Input(MathUtil::SaturatingCast<s16>(value));
break;
case ComponentFormat::Float:
+ case ComponentFormat::InvalidFloat5:
+ case ComponentFormat::InvalidFloat6:
+ case ComponentFormat::InvalidFloat7:
Input(value);
break;
}
@@ -202,7 +209,7 @@ TEST_P(VertexLoaderParamTest, PositionAll)
RunVertices(count);
- float scale = 1.f / (1u << (format == ComponentFormat::Float ? 0 : frac));
+ float scale = 1.f / (1u << (format >= ComponentFormat::Float ? 0 : frac));
for (auto iter = values.begin(); iter != values.end();)
{
float f, g;
@@ -225,6 +232,9 @@ TEST_P(VertexLoaderParamTest, PositionAll)
g = MathUtil::SaturatingCast<s16>(*iter++);
break;
case ComponentFormat::Float:
+ case ComponentFormat::InvalidFloat5:
+ case ComponentFormat::InvalidFloat6:
+ case ComponentFormat::InvalidFloat7:
f = *iter++;
g = *iter++;
break;
@@ -543,7 +553,9 @@ INSTANTIATE_TEST_SUITE_P(
::testing::Values(VertexComponentFormat::NotPresent, VertexComponentFormat::Direct,
VertexComponentFormat::Index8, VertexComponentFormat::Index16),
::testing::Values(ComponentFormat::UByte, ComponentFormat::Byte, ComponentFormat::UShort,
- ComponentFormat::Short, ComponentFormat::Float),
+ ComponentFormat::Short, ComponentFormat::Float,
+ ComponentFormat::InvalidFloat5, ComponentFormat::InvalidFloat6,
+ ComponentFormat::InvalidFloat7),
::testing::Values(NormalComponentCount::N, NormalComponentCount::NTB),
::testing::Values(false, true)));
@@ -609,7 +621,9 @@ TEST_P(VertexLoaderNormalTest, NormalAll)
Input<s16>(value * (1 << 14));
break;
case ComponentFormat::Float:
- default:
+ case ComponentFormat::InvalidFloat5:
+ case ComponentFormat::InvalidFloat6:
+ case ComponentFormat::InvalidFloat7:
Input<float>(value);
break;
}