Skip to content

Commit 8340fb9

Browse files
committed
fixup! feat(d3dx): Implement D3DXAssembleShader with precompiled shaders (TheSuperHackers#2176)
Use SrcDataLen parameter and ensure null-termination for strstr safety. D3DX8 API allows non-null-terminated input bounded by SrcDataLen. Matches Wine's D3DAssemble implementation which also null-terminates.
1 parent 5ca28ab commit 8340fb9

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

Core/Libraries/Include/Lib/D3DXCompat.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@
6868
#include <d3d8.h>
6969
#include <limits.h>
7070
#include <float.h>
71+
#include <string.h>
72+
#include <string>
7173

7274
//-----------------------------------------------------------------------------
7375
// D3DX Constants
@@ -725,11 +727,16 @@ inline HRESULT D3DXAssembleShader(
725727
if (ppCompilationErrors)
726728
*ppCompilationErrors = nullptr;
727729

728-
// Identify which shader is being assembled by matching key strings
729-
// This is safe because the game only assembles these specific shaders
730+
// Ensure null-terminated copy for safe string operations.
731+
// D3DX8 API allows non-null-terminated input bounded by SrcDataLen,
732+
// matching Wine's D3DAssemble implementation which also null-terminates.
733+
std::string srcStr(pSrcData, SrcDataLen);
734+
const char* src = srcStr.c_str();
735+
736+
// Identify which shader is being assembled by matching key strings.
730737

731738
// Shader 1: River water (has "+mul r0.a, r0, t3" - co-issued instruction)
732-
if (strstr(pSrcData, "+mul r0.a") != nullptr)
739+
if (strstr(src, "+mul r0.a") != nullptr)
733740
{
734741
*ppCompiledShader = new D3DXShaderBuffer(
735742
D3DXCompat_Shaders::shader1_bytecode,
@@ -738,7 +745,7 @@ inline HRESULT D3DXAssembleShader(
738745
}
739746

740747
// Shader 2: Water with env mapping (has "texbem")
741-
if (strstr(pSrcData, "texbem") != nullptr)
748+
if (strstr(src, "texbem") != nullptr)
742749
{
743750
*ppCompiledShader = new D3DXShaderBuffer(
744751
D3DXCompat_Shaders::shader2_bytecode,
@@ -747,16 +754,16 @@ inline HRESULT D3DXAssembleShader(
747754
}
748755

749756
// Shader 3: Trapezoid water (has "mad" instruction)
750-
if (strstr(pSrcData, "mad") != nullptr)
757+
if (strstr(src, "mad") != nullptr)
751758
{
752759
*ppCompiledShader = new D3DXShaderBuffer(
753760
D3DXCompat_Shaders::shader3_bytecode,
754761
sizeof(D3DXCompat_Shaders::shader3_bytecode));
755762
return S_OK;
756763
}
757764

758-
// Unknown shader - return error
759-
// The game will handle this gracefully and use fallback rendering
765+
// Unknown shader - return error.
766+
// The game will handle this gracefully and use fallback rendering.
760767
return E_FAIL;
761768
}
762769

0 commit comments

Comments
 (0)