Only check GetLastError() if ReadFile returns false (#13076)

This commit is contained in:
Blue 2025-06-10 11:07:16 -07:00 committed by GitHub
parent 4b6b3884ba
commit 94ecb86067
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1107,13 +1107,17 @@ std::vector<BYTE> wsl::windows::common::wslutil::HashFile(HANDLE file, DWORD Alg
std::vector<char> buffer(bufferSize);
DWORD readBytes{};
while (ReadFile(file, buffer.data(), bufferSize, &readBytes, nullptr) && readBytes > 0)
while (true)
{
THROW_IF_WIN32_BOOL_FALSE(ReadFile(file, buffer.data(), bufferSize, &readBytes, nullptr));
if (readBytes == 0)
{
break;
}
THROW_IF_WIN32_BOOL_FALSE(CryptHashData(hash.get(), reinterpret_cast<const BYTE*>(buffer.data()), readBytes, 0));
}
THROW_IF_WIN32_ERROR(GetLastError());
std::vector<BYTE> fileHash(32);
DWORD hashSize = static_cast<DWORD>(fileHash.size());