FileSystems: Reject parent directory references in savestate file names

DirectoryFileSystem reopens the open files' guest paths on load, with
their original access mode, so a crafted state could create or truncate
host files outside the memstick or game folder. VirtualDiscFileSystem had
the same problem for reads. Guest paths never contain ".." here, the meta
file system resolves them.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Henrik RydgårdandClaude Opus 5.5 committed 2026-10-09 15:32:06 +02:00
1 parent 1d18d182e1
commit 864778a11b
2 files changed
+21

No files matched your search

@@ -194,6 +194,12 @@ void VirtualDiscFileSystem::DoState(PointerWrap &p)
Do(p, entryCount);
Do(p, currentBlockIndex);
if (fileListSize < 0 || entryCount < 0 || !p.CheckRead(fileListSize)) {
ERROR_LOG(Log::FileSystem, "Savestate has an invalid file list size");
p.SetError(p.ERROR_FAILURE);
return;
}
FileListEntry dummy = {""};
fileList.resize(fileListSize, dummy);
@@ -202,6 +208,13 @@ void VirtualDiscFileSystem::DoState(PointerWrap &p)
Do(p, fileList[i].fileName);
Do(p, fileList[i].firstBlock);
Do(p, fileList[i].totalSize);
// Same check as for the index file, these get opened under basePath.
if (HasParentDirComponent(fileList[i].fileName)) {
ERROR_LOG(Log::FileSystem, "Savestate has a file name with a parent directory reference");
p.SetError(p.ERROR_FAILURE);
fileList[i].fileName.clear();
return;
}
}
if (p.mode == p.MODE_READ)