0
0
Fork 0

Validate dimensions before creating texture (#4430)

This commit is contained in:
gdkchan 2023-02-16 11:16:31 -03:00 committed by GitHub
parent a5a9b9bc8b
commit a707842e14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.