Skip to content

Commit

Permalink
GameInfoCache: Check read size before using the data.
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Jan 25, 2024
1 parent 039fb86 commit f0af76e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions UI/GameInfoCache.cpp
Expand Up @@ -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;
}
Expand Down

0 comments on commit f0af76e

Please sign in to comment.