Skip to content

Commit

Permalink
SDL: Avoid overreading shader sampler mapping arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed Jan 21, 2025
1 parent aef49b3 commit db6a38c
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions src/FNA3D_Driver_SDL.c
Original file line number Diff line number Diff line change
Expand Up @@ -1796,19 +1796,27 @@ static void SDLGPU_VerifyVertexSampler(

if (vertShader)
{
samplerType = MOJOSHADER_sdlGetShaderParseData(vertShader)->samplers[index].type;

if (samplerType == MOJOSHADER_SAMPLER_2D)
{
renderer->vertexTextureSamplerBindings[index].texture = renderer->dummyTexture2D;
}
else if (samplerType == MOJOSHADER_SAMPLER_VOLUME)
const MOJOSHADER_parseData *pd = MOJOSHADER_sdlGetShaderParseData(vertShader);
if (index < pd->sampler_count)
{
renderer->vertexTextureSamplerBindings[index].texture = renderer->dummyTexture3D;
samplerType = MOJOSHADER_sdlGetShaderParseData(vertShader)->samplers[index].type;

if (samplerType == MOJOSHADER_SAMPLER_2D)
{
renderer->vertexTextureSamplerBindings[index].texture = renderer->dummyTexture2D;
}
else if (samplerType == MOJOSHADER_SAMPLER_VOLUME)
{
renderer->vertexTextureSamplerBindings[index].texture = renderer->dummyTexture3D;
}
else
{
renderer->vertexTextureSamplerBindings[index].texture = renderer->dummyTextureCube;
}
}
else
{
renderer->vertexTextureSamplerBindings[index].texture = renderer->dummyTextureCube;
renderer->vertexTextureSamplerBindings[index].texture = renderer->dummyTexture2D;
}
}
else
Expand Down Expand Up @@ -1858,18 +1866,26 @@ static void SDLGPU_VerifySampler(

if (fragShader)
{
samplerType = MOJOSHADER_sdlGetShaderParseData(fragShader)->samplers[index].type;
if (samplerType == MOJOSHADER_SAMPLER_2D)
{
renderer->fragmentTextureSamplerBindings[index].texture = renderer->dummyTexture2D;
}
else if (samplerType == MOJOSHADER_SAMPLER_VOLUME)
const MOJOSHADER_parseData *pd = MOJOSHADER_sdlGetShaderParseData(fragShader);
if (index < pd->sampler_count)
{
renderer->fragmentTextureSamplerBindings[index].texture = renderer->dummyTexture3D;
samplerType = pd->samplers[index].type;
if (samplerType == MOJOSHADER_SAMPLER_2D)
{
renderer->fragmentTextureSamplerBindings[index].texture = renderer->dummyTexture2D;
}
else if (samplerType == MOJOSHADER_SAMPLER_VOLUME)
{
renderer->fragmentTextureSamplerBindings[index].texture = renderer->dummyTexture3D;
}
else
{
renderer->fragmentTextureSamplerBindings[index].texture = renderer->dummyTextureCube;
}
}
else
{
renderer->fragmentTextureSamplerBindings[index].texture = renderer->dummyTextureCube;
renderer->fragmentTextureSamplerBindings[index].texture = renderer->dummyTexture2D;
}
}
else
Expand Down

0 comments on commit db6a38c

Please sign in to comment.