1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Correct _calculateCRC:

calculated texture size in bytes can be too large to fit TMEM.
It leads to out-of-bounds reads in checksum calculations and thus random checksum.
Example:

Fixed Unplayable performance with any kind of texture enhancement. #2279
This commit is contained in:
Sergey Lipskiy 2020-06-14 22:59:20 +07:00
parent 7228d0d5db
commit 0c5d036395

View File

@ -1257,11 +1257,15 @@ u64 _calculateCRC(u32 _t, const TextureParams & _params, u32 _bytes)
_bytes >>= 1;
const u32 tMemMask = (gDP.otherMode.textureLUT == G_TT_NONE && !rgba32) ? 0x1FF : 0xFF;
const u64 *src = (u64*)&TMEM[gSP.textureTile[_t]->tmem & tMemMask];
const u32 maxBytes = (tMemMask + 1) << 3;
const u32 tileTmemInBytes = gSP.textureTile[_t]->tmem << 3;
if (!rgba32 && (tileTmemInBytes + _bytes > maxBytes))
_bytes = maxBytes - tileTmemInBytes;
u64 crc = UINT64_MAX;
crc = CRC_Calculate(crc, src, _bytes);
if (rgba32) {
src = (u64*)&TMEM[gSP.textureTile[_t]->tmem + 256];
src = (u64*)&TMEM[(gSP.textureTile[_t]->tmem + 256) & 0x1FF];
crc = CRC_Calculate(crc, src, _bytes);
}