aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2023-02-16 11:16:31 -0300
committerGitHub <noreply@github.com>2023-02-16 11:16:31 -0300
commita707842e14dde468781270198ae63757ca3c2716 (patch)
tree02e9c3d0e11359029d43601c236a447e4f43f7d7
parenta5a9b9bc8b64184cd4c342dea39fed5c2c058a72 (diff)
Validate dimensions before creating texture (#4430)1.1.623
-rw-r--r--Ryujinx.Graphics.Gpu/Image/TextureCache.cs18
1 files changed, 17 insertions, 1 deletions
diff --git a/Ryujinx.Graphics.Gpu/Image/TextureCache.cs b/Ryujinx.Graphics.Gpu/Image/TextureCache.cs
index f18de607..261d0603 100644
--- a/Ryujinx.Graphics.Gpu/Image/TextureCache.cs
+++ b/Ryujinx.Graphics.Gpu/Image/TextureCache.cs
@@ -477,7 +477,23 @@ namespace Ryujinx.Graphics.Gpu.Image
// If the start address is unmapped, let's try to find a page of memory that is mapped.
if (address == MemoryManager.PteUnmapped)
{
- address = memoryManager.TranslateFirstMapped(info.GpuAddress, (ulong)info.CalculateSizeInfo(layerSize).TotalSize);
+ // Make sure that the dimensions are valid before calculating the texture size.
+ if (info.Width < 1 || info.Height < 1 || info.Levels < 1)
+ {
+ return null;
+ }
+
+ if ((info.Target == Target.Texture3D ||
+ info.Target == Target.Texture2DArray ||
+ info.Target == Target.Texture2DMultisampleArray ||
+ info.Target == Target.CubemapArray) && info.DepthOrLayers < 1)
+ {
+ return null;
+ }
+
+ ulong dataSize = (ulong)info.CalculateSizeInfo(layerSize).TotalSize;
+
+ address = memoryManager.TranslateFirstMapped(info.GpuAddress, dataSize);
}
// If address is still invalid, the texture is fully unmapped, so it has no data, just return null.