Skip to content

Commit

Permalink
Fix x64 crash on SetVertexShaderConstantF index overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSnowfall committed Feb 16, 2025
1 parent e513540 commit 599073c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/d3d8/d3d8_batch.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#include <vector>
#include <cstdint>
#include <climits>

namespace dxvk {

Expand Down Expand Up @@ -83,7 +82,7 @@ namespace dxvk {
D3DPRIMITIVETYPE PrimitiveType = D3DPT_INVALID;
std::vector<uint16_t> Indices;
UINT Offset = 0;
UINT MinVertex = UINT_MAX;
UINT MinVertex = std::numeric_limits<uint32_t>::max();
UINT MaxVertex = 0;
UINT PrimitiveCount = 0;
UINT DrawCallCount = 0;
Expand Down Expand Up @@ -126,7 +125,7 @@ namespace dxvk {

draw.PrimitiveType = D3DPRIMITIVETYPE(0);
draw.Offset = 0;
draw.MinVertex = UINT_MAX;
draw.MinVertex = std::numeric_limits<uint32_t>::max();
draw.MaxVertex = 0;
draw.PrimitiveCount = 0;
draw.DrawCallCount = 0;
Expand Down
4 changes: 4 additions & 0 deletions src/d3d9/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7692,6 +7692,10 @@ namespace dxvk {
const uint32_t regCountHardware = DetermineHardwareRegCount<ProgramType, ConstantType>();
constexpr uint32_t regCountSoftware = DetermineSoftwareRegCount<ProgramType, ConstantType>();

// Error out in case of StartRegister + Count overflow
if (unlikely(StartRegister > std::numeric_limits<uint32_t>::max() - Count))
return D3DERR_INVALIDCALL;

if (unlikely(StartRegister + Count > regCountSoftware))
return D3DERR_INVALIDCALL;

Expand Down

0 comments on commit 599073c

Please sign in to comment.