From 177925be934bb64dabba17165939f12e2c7d5c6c Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 8 Jan 2023 19:28:00 +0000 Subject: [PATCH] Avoid OOB memory acceses when trying to read OOB TICs Some games pass in invalid texture handles (0xffff) when they don't need the texture so return the null texture in this case. --- .../cpp/skyline/gpu/interconnect/common/textures.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/cpp/skyline/gpu/interconnect/common/textures.cpp b/app/src/main/cpp/skyline/gpu/interconnect/common/textures.cpp index 60b4c50b..b6d57a07 100644 --- a/app/src/main/cpp/skyline/gpu/interconnect/common/textures.cpp +++ b/app/src/main/cpp/skyline/gpu/interconnect/common/textures.cpp @@ -225,7 +225,8 @@ namespace skyline::gpu::interconnect { if (textureHeaderCache.size() != textureHeaders.size()) { textureHeaderCache.resize(textureHeaders.size()); std::fill(textureHeaderCache.begin(), textureHeaderCache.end(), CacheEntry{}); - } else if (auto &cached{textureHeaderCache[index]}; cached.view) { + } else if (textureHeaders.size() > index && textureHeaderCache[index].view) { + auto &cached{textureHeaderCache[index]}; if (cached.executionTag == ctx.executor.executionTag) return cached.view; @@ -235,6 +236,13 @@ namespace skyline::gpu::interconnect { } } + if (index >= textureHeaders.size()) { + if (!nullTextureView) + nullTextureView = CreateNullTexture(ctx); + + return nullTextureView.get(); + } + TextureImageControl &textureHeader{textureHeaders[index]}; auto &texture{textureHeaderStore[textureHeader]};