GameInfoCache: Check read size before using the data.

This commit is contained in:
Henrik Rydgård
2024-01-25 09:43:06 +01:00
parent 039fb86e9c
commit f0af76ec40
+8 -3
View File
@@ -351,15 +351,20 @@ static bool ReadFileToString(IFileSystem *fs, const char *filename, std::string
if (mtx) {
std::string data;
data.resize(info.size);
fs->ReadFile(handle, (u8 *)data.data(), info.size);
size_t readSize = fs->ReadFile(handle, (u8 *)data.data(), info.size);
fs->CloseFile(handle);
if (readSize != info.size) {
return false;
}
std::lock_guard<std::mutex> lock(*mtx);
*contents = std::move(data);
} else {
contents->resize(info.size);
fs->ReadFile(handle, (u8 *)contents->data(), info.size);
size_t readSize = fs->ReadFile(handle, (u8 *)contents->data(), info.size);
fs->CloseFile(handle);
if (readSize != info.size) {
return false;
}
}
return true;
}