From 942021e5cd54e3c796545060e70caa03df2088a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 4 May 2023 23:47:46 +0200 Subject: [PATCH 1/5] VirtualDiscFileSystem: Fix out-of-range array read in fileList --- Core/FileSystems/VirtualDiscFileSystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/FileSystems/VirtualDiscFileSystem.cpp b/Core/FileSystems/VirtualDiscFileSystem.cpp index d141b5a4199b..42684a0fc2c4 100644 --- a/Core/FileSystems/VirtualDiscFileSystem.cpp +++ b/Core/FileSystems/VirtualDiscFileSystem.cpp @@ -645,7 +645,7 @@ PSPFileInfo VirtualDiscFileSystem::GetFileInfo(std::string filename) { localtime_r((time_t*)&mtime, &x.mtime); } - x.startSector = fileList[fileIndex].firstBlock; + // x.startSector was set above in "if (fileIndex != -1)". x.numSectors = (x.size+2047)/2048; } From 9a2ca4836abf0a518ae8ea3273f4ffa47413f3f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 4 May 2023 23:54:59 +0200 Subject: [PATCH 2/5] Add missing locking to AsyncIOManager --- Core/HW/AsyncIOManager.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Core/HW/AsyncIOManager.cpp b/Core/HW/AsyncIOManager.cpp index 85a98860538a..8718bcbdb081 100644 --- a/Core/HW/AsyncIOManager.cpp +++ b/Core/HW/AsyncIOManager.cpp @@ -29,6 +29,7 @@ #include "Core/FileSystems/MetaFileSystem.h" bool AsyncIOManager::HasOperation(u32 handle) { + std::lock_guard guard(resultsLock_); if (resultsPending_.find(handle) != resultsPending_.end()) { return true; } @@ -60,6 +61,7 @@ bool AsyncIOManager::HasResult(u32 handle) { } bool AsyncIOManager::PopResult(u32 handle, AsyncIOResult &result) { + // This is called under lock from WaitResult, no need to lock again. if (results_.find(handle) != results_.end()) { result = results_[handle]; results_.erase(handle); @@ -75,6 +77,7 @@ bool AsyncIOManager::PopResult(u32 handle, AsyncIOResult &result) { } bool AsyncIOManager::ReadResult(u32 handle, AsyncIOResult &result) { + // This is called under lock from WaitResult, no need to lock again. if (results_.find(handle) != results_.end()) { result = results_[handle]; return true; From 1bd7da221bf9f995c0925bedcc84654583e03a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 5 May 2023 00:00:11 +0200 Subject: [PATCH 3/5] Fix obscure crash possibility (call stack found), some clarification --- UI/GameSettingsScreen.cpp | 2 +- UI/MemStickScreen.h | 2 -- UI/MiscScreens.cpp | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 77553ab31391..a427f12dcefa 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -1420,7 +1420,7 @@ void GameSettingsScreen::dialogFinished(const Screen *dialog, DialogResult resul } void GameSettingsScreen::RecreateViews() { - oldSettingInfo_ = settingInfo_->GetText(); + oldSettingInfo_ = settingInfo_ ? settingInfo_->GetText() : "N/A"; UIScreen::RecreateViews(); } diff --git a/UI/MemStickScreen.h b/UI/MemStickScreen.h index 3912e095bc6a..ae0a22c1a72a 100644 --- a/UI/MemStickScreen.h +++ b/UI/MemStickScreen.h @@ -74,8 +74,6 @@ class MemStickScreen : public UIDialogScreenWithBackground { UI::EventReturn OnConfirmClick(UI::EventParams ¶ms); UI::EventReturn OnChoiceClick(UI::EventParams ¶ms); - SettingInfoMessage *settingInfo_ = nullptr; - bool initialSetup_; bool storageBrowserWorking_; bool done_ = false; diff --git a/UI/MiscScreens.cpp b/UI/MiscScreens.cpp index 527cfe39b672..6754c0a14b64 100644 --- a/UI/MiscScreens.cpp +++ b/UI/MiscScreens.cpp @@ -1114,5 +1114,5 @@ void SettingInfoMessage::Draw(UIContext &dc) { } std::string SettingInfoMessage::GetText() const { - return showing_ && text_ ? text_->GetText() : ""; + return (showing_ && text_) ? text_->GetText() : ""; } From 38178d34b523b4663b73dd763c9a907b74591035 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 5 May 2023 00:03:20 +0200 Subject: [PATCH 4/5] Sanity checks in InitSwapchain --- Common/GPU/Vulkan/VulkanContext.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Common/GPU/Vulkan/VulkanContext.cpp b/Common/GPU/Vulkan/VulkanContext.cpp index c1531801cacb..e57345cfab6d 100644 --- a/Common/GPU/Vulkan/VulkanContext.cpp +++ b/Common/GPU/Vulkan/VulkanContext.cpp @@ -1199,6 +1199,12 @@ static std::string surface_transforms_to_string(VkSurfaceTransformFlagsKHR trans } bool VulkanContext::InitSwapchain() { + _assert_(physical_device_ >= 0 && physical_device_ < physical_devices_.size()); + if (!surface_) { + ERROR_LOG(G3D, "VK: No surface, can't create swapchain"); + return false; + } + VkResult res = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_devices_[physical_device_], surface_, &surfCapabilities_); if (res == VK_ERROR_SURFACE_LOST_KHR) { // Not much to do. From 0b94ffc4c19d1b811b38852cb003cac56837d940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Fri, 5 May 2023 01:18:29 +0200 Subject: [PATCH 5/5] Buildfix attempt --- UI/MemStickScreen.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/UI/MemStickScreen.h b/UI/MemStickScreen.h index ae0a22c1a72a..3912e095bc6a 100644 --- a/UI/MemStickScreen.h +++ b/UI/MemStickScreen.h @@ -74,6 +74,8 @@ class MemStickScreen : public UIDialogScreenWithBackground { UI::EventReturn OnConfirmClick(UI::EventParams ¶ms); UI::EventReturn OnChoiceClick(UI::EventParams ¶ms); + SettingInfoMessage *settingInfo_ = nullptr; + bool initialSetup_; bool storageBrowserWorking_; bool done_ = false;