Limit size of loaded file systems

If a disc image is malformed in a specific way, Dolphin
will try to allocate a lot of memory, making it crash.
To avoid that, this change adds an artificial limit for
the size of file systems that Dolphin will try to load.
This commit is contained in:
JosJuice 2015-10-04 10:17:43 +02:00
parent 5228758383
commit 6c25c63301
1 changed files with 12 additions and 0 deletions

View File

@ -276,6 +276,18 @@ void CFileSystemGCWii::InitFileSystem()
if (!Root.IsDirectory()) if (!Root.IsDirectory())
return; 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()) if (m_FileInfoVector.size())
PanicAlert("Wtf?"); PanicAlert("Wtf?");
u64 NameTableOffset = FSTOffset; u64 NameTableOffset = FSTOffset;