From a943600019969ce0382821e7ee19ef4b990564cb Mon Sep 17 00:00:00 2001 From: v1993 Date: Mon, 17 Jan 2022 12:45:34 +0300 Subject: shader_recompiler: fix potential OOB access Found by static analysis with PVS-Studio. Original check wasn't actually checking for OOB and would segfault in case of it. --- src/shader_recompiler/backend/spirv/spirv_emit_context.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/shader_recompiler/backend/spirv') diff --git a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp index d3ba66569..cd90c084a 100644 --- a/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp +++ b/src/shader_recompiler/backend/spirv/spirv_emit_context.cpp @@ -164,9 +164,10 @@ void DefineGenericOutput(EmitContext& ctx, size_t index, std::optional invo while (element < 4) { const u32 remainder{4 - element}; const TransformFeedbackVarying* xfb_varying{}; - if (!ctx.runtime_info.xfb_varyings.empty()) { - xfb_varying = &ctx.runtime_info.xfb_varyings[base_attr_index + element]; - xfb_varying = xfb_varying && xfb_varying->components > 0 ? xfb_varying : nullptr; + const size_t xfb_varying_index{base_attr_index + element}; + if (xfb_varying_index < ctx.runtime_info.xfb_varyings.size()) { + xfb_varying = &ctx.runtime_info.xfb_varyings[xfb_varying_index]; + xfb_varying = xfb_varying->components > 0 ? xfb_varying : nullptr; } const u32 num_components{xfb_varying ? xfb_varying->components : remainder}; -- cgit v1.2.3