From 6c25c633014ce8bdf8b8a4d9562aca646ba5f051 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 4 Oct 2015 10:17:43 +0200 Subject: [PATCH] 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. --- Source/Core/DiscIO/FileSystemGCWii.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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;