From f3c1fa7c05e7f29914be403d0f87cee95383236b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 31 Mar 2025 12:30:47 +0200 Subject: [PATCH] Quick sanity check for EBOOT deletion. Fixes #20187, although arguably we should be even stricter. --- Core/System.h | 1 + UI/GameInfoCache.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Core/System.h b/Core/System.h index 3ca344ee86..f867c746aa 100644 --- a/Core/System.h +++ b/Core/System.h @@ -58,6 +58,7 @@ enum PSPDirectories { DIRECTORY_EXDATA, DIRECTORY_CUSTOM_SHADERS, DIRECTORY_CUSTOM_THEMES, + COUNT, }; class GraphicsContext; diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index eb8b9ff4ab..4b099a4f15 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -73,6 +73,19 @@ GameInfo::~GameInfo() { fileLoader.reset(); } +bool IsReasonableEbootDirectory(Path path) { + // First some sanity checks. + if (path == Path("/")) { + return false; + } + for (int i = 0; i < (int)PSPDirectories::COUNT; i++) { + if (path == GetSysDirectory((PSPDirectories)i)) { + return false; + } + } + return true; +} + bool GameInfo::Delete() { switch (fileType) { case IdentifiedFileType::PSP_ISO: @@ -90,6 +103,17 @@ bool GameInfo::Delete() { { // TODO: This could be handled by Core/Util/GameManager too somehow. Path directoryToRemove = ResolvePBPDirectory(filePath_); + + // Check that the directory isn't the base of the GAME folder, or something similarly stupid. + // This can happen if the PBP is misplaced, see issue #20187 + if (!IsReasonableEbootDirectory(directoryToRemove)) { + // Just delete the eboot. + File::Delete(filePath_); + g_recentFiles.Remove(filePath_.ToString()); + return true; + } + + // Delete the whole tree. We better be sure, see IsReasonableEbootDirectory. INFO_LOG(Log::System, "Deleting directory %s", directoryToRemove.c_str()); if (!File::DeleteDirRecursively(directoryToRemove)) { ERROR_LOG(Log::System, "Failed to delete file");