From 9e106e1d3d18e4360e8557a68af918c856eb9bd9 Mon Sep 17 00:00:00 2001 From: Sean McGovern Date: Tue, 11 May 2021 23:40:49 -0400 Subject: [PATCH] FileUtil: check for errors after a fread() in ReadFileToString() --- Common/File/FileUtil.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Common/File/FileUtil.cpp b/Common/File/FileUtil.cpp index 5262ffa948..9d0a1b518f 100644 --- a/Common/File/FileUtil.cpp +++ b/Common/File/FileUtil.cpp @@ -896,7 +896,8 @@ bool ReadFileToString(bool text_file, const char *filename, std::string &str) { success = true; } else { str.resize(len); - success = fread(&str[0], 1, len, f) == len; + int read = fread(&str[0], 1, len, f); + success = read <= len && !ferror(f); } fclose(f); return success;