From 1f69d427fbfa4595335bb742e7ea63837820e17d Mon Sep 17 00:00:00 2001 From: John Machado Date: Thu, 21 Dec 2023 11:49:28 +0530 Subject: [PATCH] Fix possible integer overflow --- Source/GmmLib/Texture/GmmTextureOffset.cpp | 10 +++++----- Source/GmmLib/Texture/GmmXe_LPGTexture.cpp | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/GmmLib/Texture/GmmTextureOffset.cpp b/Source/GmmLib/Texture/GmmTextureOffset.cpp index da495ba..95d4aaf 100644 --- a/Source/GmmLib/Texture/GmmTextureOffset.cpp +++ b/Source/GmmLib/Texture/GmmTextureOffset.cpp @@ -237,7 +237,7 @@ GMM_STATUS GmmLib::GmmTextureCalc::GetTexStdLayoutOffset(GMM_TEXTURE_INFO * pT pReqInfo->StdLayout.TileDepthPitch = DepthPitch; } - PrevMipSize = DepthPitch * MipDepthTiles; + PrevMipSize = (GMM_GFX_SIZE_T)DepthPitch * MipDepthTiles; SlicePitch += DepthPitch; } @@ -352,12 +352,12 @@ GMM_STATUS GmmLib::GmmTextureCalc::GetTexLockOffset(GMM_TEXTURE_INFO * pTexInf pReqInfo->Lock.Mip0SlicePitch = GFX_ULONG_CAST(pTexInfo->OffsetInfo.Texture3DOffsetInfo.Mip0SlicePitch); // Actual address is offset based on requested slice - AddressOffset += SliceRow * MipHeight * Pitch; + AddressOffset += (GMM_GFX_SIZE_T)SliceRow * MipHeight * Pitch; // Get to particular slice if(Slice % NumberOfMipsInSingleRow) { - AddressOffset += (((Slice % NumberOfMipsInSingleRow) * + AddressOffset += (((GMM_GFX_SIZE_T)(Slice % NumberOfMipsInSingleRow) * MipWidth * pTexInfo->BitsPerPixel) >> 3); } @@ -788,9 +788,9 @@ GMM_GFX_SIZE_T GmmLib::GmmTextureCalc::Get3DMipByteAddress(GMM_TEXTURE_INFO * MipHeight /= 2; } - ExtraBytes = PlaneRows * MipHeight * Pitch; + ExtraBytes = (GMM_GFX_SIZE_T)PlaneRows * MipHeight * Pitch; - ExtraBytes += ((Slice % MipsInThisRow) * + ExtraBytes += ((GMM_GFX_SIZE_T)(Slice % MipsInThisRow) * MipWidth * pTexInfo->BitsPerPixel) >> 3; diff --git a/Source/GmmLib/Texture/GmmXe_LPGTexture.cpp b/Source/GmmLib/Texture/GmmXe_LPGTexture.cpp index d689c3d..213ce29 100644 --- a/Source/GmmLib/Texture/GmmXe_LPGTexture.cpp +++ b/Source/GmmLib/Texture/GmmXe_LPGTexture.cpp @@ -1024,12 +1024,12 @@ GMM_STATUS GmmLib::GmmXe_LPGTextureCalc::GetTexLockOffset(GMM_TEXTURE_INFO * p pReqInfo->Lock.Mip0SlicePitch = GFX_ULONG_CAST(pTexInfo->OffsetInfo.Texture3DOffsetInfo.Mip0SlicePitch); // Actual address is offset based on requested slice - AddressOffset += SliceRow * MipHeight * Pitch; + AddressOffset += (GMM_GFX_SIZE_T)SliceRow * MipHeight * Pitch; // Get to particular slice if(Slice % NumberOfMipsInSingleRow) { - AddressOffset += (((Slice % NumberOfMipsInSingleRow) * + AddressOffset += (((GMM_GFX_SIZE_T)(Slice % NumberOfMipsInSingleRow) * MipWidth * pTexInfo->BitsPerPixel) >> 3); }