summaryrefslogtreecommitdiff
path: root/Source/Core/DiscIO/FileSystemGCWii.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/DiscIO/FileSystemGCWii.cpp')
-rw-r--r--Source/Core/DiscIO/FileSystemGCWii.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/Source/Core/DiscIO/FileSystemGCWii.cpp b/Source/Core/DiscIO/FileSystemGCWii.cpp
index e20d633f35..614df0a32b 100644
--- a/Source/Core/DiscIO/FileSystemGCWii.cpp
+++ b/Source/Core/DiscIO/FileSystemGCWii.cpp
@@ -276,6 +276,18 @@ void CFileSystemGCWii::InitFileSystem()
if (!Root.IsDirectory())
return;
+ // 12 bytes (the size of a file entry) times 10 * 1024 * 1024 is 120 MiB,
+ // more than total RAM in a Wii. No file system should use anywhere near that much.
+ static const u32 ARBITRARY_FILE_SYSTEM_SIZE_LIMIT = 10 * 1024 * 1024;
+ if (Root.m_FileSize > ARBITRARY_FILE_SYSTEM_SIZE_LIMIT)
+ {
+ // Without this check, Dolphin can crash by trying to allocate too much
+ // memory when loading the file systems of certain malformed disc images.
+
+ ERROR_LOG(DISCIO, "File system is abnormally large! Aborting loading");
+ return;
+ }
+
if (m_FileInfoVector.size())
PanicAlert("Wtf?");
u64 NameTableOffset = FSTOffset;