From f0af76ec40faa294a6ed7c4a3728b1a6d2feffe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 25 Jan 2024 09:43:06 +0100 Subject: [PATCH] GameInfoCache: Check read size before using the data. --- UI/GameInfoCache.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index 199ff42aab..fed466f3c0 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -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 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; }