1
0
mirror of https://github.com/microsoft/DirectXTex synced 2024-11-24 13:20:13 +00:00

Add check for unexpected EOF to LoadDDSTextureFromFile

This commit is contained in:
Chuck Walbourn 2022-04-06 00:40:10 -07:00
parent bc1aecbcf8
commit b736e9edc3

View File

@ -1944,11 +1944,18 @@ HRESULT DirectX::LoadFromDDSFile(
} }
#ifdef WIN32 #ifdef WIN32
if (!ReadFile(hFile.get(), image.GetPixels(), static_cast<DWORD>(image.GetPixelsSize()), &bytesRead, nullptr)) auto pixelBytes = static_cast<DWORD>(image.GetPixelsSize());
if (!ReadFile(hFile.get(), image.GetPixels(), pixelBytes, &bytesRead, nullptr))
{ {
image.Release(); image.Release();
return HRESULT_FROM_WIN32(GetLastError()); return HRESULT_FROM_WIN32(GetLastError());
} }
if (bytesRead != pixelBytes)
{
image.Release();
return E_FAIL;
}
#else #else
inFile.read(reinterpret_cast<char*>(image.GetPixels()), image.GetPixelsSize()); inFile.read(reinterpret_cast<char*>(image.GetPixels()), image.GetPixelsSize());
if (!inFile) if (!inFile)