From cc3d2d21efef2d06c6a2f29d2eb0bc31eb1b10b6 Mon Sep 17 00:00:00 2001 From: Alberto Ruiz Date: Wed, 30 Sep 2026 23:14:16 +0200 Subject: [PATCH] fix(shader): skip the push constant copy when there is nothing to copy decodeResult and decodeAllocation called memcpy with the data() of empty vectors, which may be null. Passing a null pointer to memcpy is undefined even for a zero size, and UBSan reports it on every entry without push constants, including the existing shader disk cache test. The copy now runs only for a non-empty table, as Reader::Values does. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01R5WJS4ZdQynAJesCZKH5hb --- core/shader/recompiler/ShaderDiskCache.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/shader/recompiler/ShaderDiskCache.cpp b/core/shader/recompiler/ShaderDiskCache.cpp index 932ebf10f..1ab604ad9 100644 --- a/core/shader/recompiler/ShaderDiskCache.cpp +++ b/core/shader/recompiler/ShaderDiskCache.cpp @@ -305,7 +305,7 @@ void decodeResult(Reader& reader, RecompileResult& result) { std::vector pushConstants; reader.Values(pushConstants); result.pushConstants.resize(pushConstants.size()); - std::memcpy(result.pushConstants.data(), pushConstants.data(), pushConstants.size()); + if (!pushConstants.empty()) std::memcpy(result.pushConstants.data(), pushConstants.data(), pushConstants.size()); reader.Value(result.bdaAbiVersion); reader.Value(result.memoryOffsetDword); reader.List(result.vertexAttributes, 28, [](Reader& in, VertexAttribute& attribute) { @@ -546,7 +546,7 @@ void decodeAllocation(Reader& reader, BindingAllocationResult& allocation) { std::vector pushConstants; reader.Values(pushConstants); allocation.pushConstants.resize(pushConstants.size()); - std::memcpy(allocation.pushConstants.data(), pushConstants.data(), pushConstants.size()); + if (!pushConstants.empty()) std::memcpy(allocation.pushConstants.data(), pushConstants.data(), pushConstants.size()); } constexpr std::string_view NeutralSwitches[] = {