From 88e13d8326e7c13ee8ccddcfd840ca174f59b996 Mon Sep 17 00:00:00 2001 From: kd-11 Date: Sat, 4 Jan 2025 02:00:14 +0300 Subject: [PATCH] rsx: Don't crash when invalid buffer is allocated for a shader --- rpcs3/Emu/RSX/Program/ProgramStateCache.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rpcs3/Emu/RSX/Program/ProgramStateCache.h b/rpcs3/Emu/RSX/Program/ProgramStateCache.h index f80f9eeeec..6a2c53ae93 100644 --- a/rpcs3/Emu/RSX/Program/ProgramStateCache.h +++ b/rpcs3/Emu/RSX/Program/ProgramStateCache.h @@ -293,10 +293,10 @@ public: bool compile_async, bool allow_notification, Args&& ...args - ) + ) { - const auto &vp_search = search_vertex_program(vertexShader); - const auto &fp_search = search_fragment_program(fragmentShader); + const auto& vp_search = search_vertex_program(vertexShader); + const auto& fp_search = search_fragment_program(fragmentShader); const bool already_existing_fragment_program = std::get<1>(fp_search); const bool already_existing_vertex_program = std::get<1>(vp_search); @@ -385,7 +385,13 @@ public: void fill_fragment_constants_buffer(std::span dst_buffer, const fragment_program_type& fragment_program, const RSXFragmentProgram& rsx_prog, bool sanitize = false) const { - ensure((dst_buffer.size_bytes() >= ::narrow(fragment_program.FragmentConstantOffsetCache.size()) * 16u)); + if (dst_buffer.size_bytes() < (fragment_program.FragmentConstantOffsetCache.size() * 16)) + { + // This can happen if CELL alters the shader after it has been loaded by RSX. + rsx_log.error("Insufficient constants buffer size passed to fragment program! Corrupt shader?"); + return; + } + rsx::write_fragment_constants_to_buffer(dst_buffer, rsx_prog, fragment_program.FragmentConstantOffsetCache, sanitize); }