Don't allow TGA reader to read images larger than 4GB even in 64-bit (#440)
This commit is contained in:
Родитель
4790ba43e3
Коммит
eb172c521a
|
@ -115,6 +115,9 @@ namespace DirectX
|
|||
|
||||
CP_FLAGS_8BPP = 0x40000,
|
||||
// Override with a legacy 8 bits-per-pixel format size
|
||||
|
||||
CP_FLAGS_LIMIT_4GB = 0x10000000,
|
||||
// Don't allow pixel allocations in excess of 4GB (always true for 32-bit)
|
||||
};
|
||||
|
||||
HRESULT __cdecl ComputePitch(
|
||||
|
|
|
@ -715,7 +715,7 @@ HRESULT DirectX::LoadFromHDRMemory(const void* pSource, size_t size, TexMetadata
|
|||
if (remaining == 0)
|
||||
return E_FAIL;
|
||||
|
||||
hr = image.Initialize2D(mdata.format, mdata.width, mdata.height, 1, 1);
|
||||
hr = image.Initialize2D(mdata.format, mdata.width, mdata.height, 1, 1, CP_FLAGS_LIMIT_4GB);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
|
|
|
@ -123,6 +123,12 @@ HRESULT DirectX::Internal::DetermineImageArray(
|
|||
}
|
||||
#else
|
||||
static_assert(sizeof(size_t) == 8, "Not a 64-bit platform!");
|
||||
|
||||
if ((cpFlags & CP_FLAGS_LIMIT_4GB) && (totalPixelSize > UINT32_MAX))
|
||||
{
|
||||
nImages = pixelSize = 0;
|
||||
return HRESULT_E_ARITHMETIC_OVERFLOW;
|
||||
}
|
||||
#endif
|
||||
|
||||
nImages = nimages;
|
||||
|
|
|
@ -1683,7 +1683,7 @@ HRESULT DirectX::LoadFromTGAMemory(
|
|||
|
||||
const void* pPixels = static_cast<const uint8_t*>(pSource) + offset + paletteOffset;
|
||||
|
||||
hr = image.Initialize2D(mdata.format, mdata.width, mdata.height, 1, 1);
|
||||
hr = image.Initialize2D(mdata.format, mdata.width, mdata.height, 1, 1, CP_FLAGS_LIMIT_4GB);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
|
@ -1856,7 +1856,7 @@ HRESULT DirectX::LoadFromTGAFile(
|
|||
#endif
|
||||
}
|
||||
|
||||
hr = image.Initialize2D(mdata.format, mdata.width, mdata.height, 1, 1);
|
||||
hr = image.Initialize2D(mdata.format, mdata.width, mdata.height, 1, 1, CP_FLAGS_LIMIT_4GB);
|
||||
if (FAILED(hr))
|
||||
return hr;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче