From 97b94acd866385fe79d700c1532539cc160ef9f3 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 1 Oct 2021 15:48:04 +1000 Subject: [PATCH] CDVD: Fix possible uncaught exception in CheckDiskTypeFS --- pcsx2/CDVD/CDVDaccess.cpp | 68 +++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/pcsx2/CDVD/CDVDaccess.cpp b/pcsx2/CDVD/CDVDaccess.cpp index 7a97755b51..3fcc5e9c1c 100644 --- a/pcsx2/CDVD/CDVDaccess.cpp +++ b/pcsx2/CDVD/CDVDaccess.cpp @@ -77,45 +77,51 @@ static void CheckNullCDVD() static int CheckDiskTypeFS(int baseType) { IsoFSCDVD isofs; - IsoDirectory rootdir(isofs); try { - IsoFile file(rootdir, L"SYSTEM.CNF;1"); + IsoDirectory rootdir(isofs); - int size = file.getLength(); - - std::unique_ptr buffer(new char[file.getLength() + 1]); - file.read(buffer.get(), size); - buffer[size] = '\0'; - - char* pos = strstr(buffer.get(), "BOOT2"); - if (pos == NULL) + try { - pos = strstr(buffer.get(), "BOOT"); + IsoFile file(rootdir, L"SYSTEM.CNF;1"); + + const int size = file.getLength(); + const std::unique_ptr buffer = std::make_unique(size + 1); + file.read(buffer.get(), size); + buffer[size] = '\0'; + + char* pos = strstr(buffer.get(), "BOOT2"); if (pos == NULL) - return CDVD_TYPE_ILLEGAL; - return CDVD_TYPE_PSCD; + { + pos = strstr(buffer.get(), "BOOT"); + if (pos == NULL) + return CDVD_TYPE_ILLEGAL; + return CDVD_TYPE_PSCD; + } + + return (baseType == CDVD_TYPE_DETCTCD) ? CDVD_TYPE_PS2CD : CDVD_TYPE_PS2DVD; + } + catch (Exception::FileNotFound&) + { } - return (baseType == CDVD_TYPE_DETCTCD) ? CDVD_TYPE_PS2CD : CDVD_TYPE_PS2DVD; - } - catch (Exception::FileNotFound&) - { - } + try + { + IsoFile file(rootdir, L"PSX.EXE;1"); + return CDVD_TYPE_PSCD; + } + catch (Exception::FileNotFound&) + { + } - try - { - IsoFile file(rootdir, L"PSX.EXE;1"); - return CDVD_TYPE_PSCD; - } - catch (Exception::FileNotFound&) - { - } - - try - { - IsoFile file(rootdir, L"VIDEO_TS/VIDEO_TS.IFO;1"); - return CDVD_TYPE_DVDV; + try + { + IsoFile file(rootdir, L"VIDEO_TS/VIDEO_TS.IFO;1"); + return CDVD_TYPE_DVDV; + } + catch (Exception::FileNotFound&) + { + } } catch (Exception::FileNotFound&) {