Missing offset boundary check in TGA reader (#429)

This commit is contained in:
Chuck Walbourn 2023-12-28 23:30:25 -08:00 committed by GitHub
parent dd5517fd06
commit eb594ad36c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1658,7 +1658,7 @@ HRESULT DirectX::LoadFromTGAMemory(
return hr; return hr;
if (offset > size) if (offset > size)
return E_FAIL; return HRESULT_E_INVALID_DATA;
size_t paletteOffset = 0; size_t paletteOffset = 0;
uint8_t palette[256 * 4] = {}; uint8_t palette[256 * 4] = {};
@ -1832,6 +1832,9 @@ HRESULT DirectX::LoadFromTGAFile(
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
if (offset > len)
return HRESULT_E_INVALID_DATA;
// Read the pixels // Read the pixels
auto const remaining = len - offset; auto const remaining = len - offset;
if (remaining == 0) if (remaining == 0)