From cb42a0329952471e5fe58f363b87f33adb297ee0 Mon Sep 17 00:00:00 2001 From: Yann Hodiesne Date: Fri, 17 Feb 2023 11:56:07 +0100 Subject: [PATCH 1/2] Check the input and destination paths before converting a game file onto itself Before these changes you could tell Dolphin to convert a game file into the same format it is already in, leading to the FileDialog using the input path as the default destination path An unsuspecting user could then click Save and Dolphin would try to convert the input file by writing the destination file on top of it... leading to an I/O error and the input file being entirely removed --- Source/Core/DolphinQt/ConvertDialog.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Source/Core/DolphinQt/ConvertDialog.cpp b/Source/Core/DolphinQt/ConvertDialog.cpp index c5bb6d6346..1535a4fe3f 100644 --- a/Source/Core/DolphinQt/ConvertDialog.cpp +++ b/Source/Core/DolphinQt/ConvertDialog.cpp @@ -4,6 +4,7 @@ #include "DolphinQt/ConvertDialog.h" #include +#include #include #include #include @@ -22,6 +23,7 @@ #include "Common/Assert.h" #include "Common/Logging/Log.h" +#include "Common/StringUtil.h" #include "DiscIO/Blob.h" #include "DiscIO/DiscUtils.h" #include "DiscIO/ScrubbedBlob.h" @@ -410,6 +412,21 @@ void ConvertDialog::Convert() } } + if (std::filesystem::exists(StringToPath(dst_path.toStdString()))) + { + std::error_code ec; + if (std::filesystem::equivalent(StringToPath(dst_path.toStdString()), + StringToPath(original_path), ec)) + { + ModalMessageBox::critical( + this, tr("Error"), + tr("The destination file cannot be the same as the source file\n\n" + "Please select another destination path for \"%1\"") + .arg(QString::fromStdString(original_path))); + continue; + } + } + ParallelProgressDialog progress_dialog(tr("Converting..."), tr("Abort"), 0, 100, this); progress_dialog.GetRaw()->setWindowModality(Qt::WindowModal); progress_dialog.GetRaw()->setWindowTitle(tr("Progress")); From 49e897422fbf42fdb866cbcc0feaa3c0e9fe47d2 Mon Sep 17 00:00:00 2001 From: Yann Hodiesne Date: Fri, 17 Feb 2023 14:36:41 +0100 Subject: [PATCH 2/2] Use a success count instead of files count --- Source/Core/DolphinQt/ConvertDialog.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Source/Core/DolphinQt/ConvertDialog.cpp b/Source/Core/DolphinQt/ConvertDialog.cpp index 1535a4fe3f..85b48edb6c 100644 --- a/Source/Core/DolphinQt/ConvertDialog.cpp +++ b/Source/Core/DolphinQt/ConvertDialog.cpp @@ -387,6 +387,8 @@ void ConvertDialog::Convert() return; } + int success_count = 0; + for (const auto& file : m_files) { const auto original_path = file->GetFilePath(); @@ -524,11 +526,13 @@ void ConvertDialog::Convert() tr("Dolphin failed to complete the requested action.")); return; } + + success_count++; } } ModalMessageBox::information(this, tr("Success"), - tr("Successfully converted %n image(s).", "", m_files.size())); + tr("Successfully converted %n image(s).", "", success_count)); close(); }