From 599073c2374738694885e3c2d6be6129255aede6 Mon Sep 17 00:00:00 2001 From: WinterSnowfall Date: Sat, 15 Feb 2025 13:43:40 +0200 Subject: [PATCH] Fix x64 crash on SetVertexShaderConstantF index overflow --- src/d3d8/d3d8_batch.h | 5 ++--- src/d3d9/d3d9_device.cpp | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/d3d8/d3d8_batch.h b/src/d3d8/d3d8_batch.h index 567e0d70b559..d9120a49c603 100644 --- a/src/d3d8/d3d8_batch.h +++ b/src/d3d8/d3d8_batch.h @@ -6,7 +6,6 @@ #include #include -#include namespace dxvk { @@ -83,7 +82,7 @@ namespace dxvk { D3DPRIMITIVETYPE PrimitiveType = D3DPT_INVALID; std::vector Indices; UINT Offset = 0; - UINT MinVertex = UINT_MAX; + UINT MinVertex = std::numeric_limits::max(); UINT MaxVertex = 0; UINT PrimitiveCount = 0; UINT DrawCallCount = 0; @@ -126,7 +125,7 @@ namespace dxvk { draw.PrimitiveType = D3DPRIMITIVETYPE(0); draw.Offset = 0; - draw.MinVertex = UINT_MAX; + draw.MinVertex = std::numeric_limits::max(); draw.MaxVertex = 0; draw.PrimitiveCount = 0; draw.DrawCallCount = 0; diff --git a/src/d3d9/d3d9_device.cpp b/src/d3d9/d3d9_device.cpp index 5947079ceaa5..7059ecce5044 100644 --- a/src/d3d9/d3d9_device.cpp +++ b/src/d3d9/d3d9_device.cpp @@ -7692,6 +7692,10 @@ namespace dxvk { const uint32_t regCountHardware = DetermineHardwareRegCount(); constexpr uint32_t regCountSoftware = DetermineSoftwareRegCount(); + // Error out in case of StartRegister + Count overflow + if (unlikely(StartRegister > std::numeric_limits::max() - Count)) + return D3DERR_INVALIDCALL; + if (unlikely(StartRegister + Count > regCountSoftware)) return D3DERR_INVALIDCALL;