From 8a1902e5a8f5c0f4568d93dd0c5a8145c39892f4 Mon Sep 17 00:00:00 2001 From: Flyinghead Date: Tue, 10 Jan 2023 11:28:42 +0100 Subject: [PATCH] GDI's and gdrom CHD's must have at least 3 tracks --- core/imgread/chd.cpp | 9 ++++++--- core/imgread/gdi.cpp | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/core/imgread/chd.cpp b/core/imgread/chd.cpp index 776ebeac6..4a5c7e075 100644 --- a/core/imgread/chd.cpp +++ b/core/imgread/chd.cpp @@ -203,11 +203,14 @@ void CHDDisc::tryOpen(const char* file) tracks.push_back(t); } - if (isGdrom && (total_frames != 549300 || tracks.size() < 3)) - WARN_LOG(GDROM, "WARNING: chd: Total GD-Rom frames is wrong: %u frames (549300 expected) in %zu tracks", total_frames, tracks.size()); - if (isGdrom) + { + if (total_frames != 549300) + WARN_LOG(GDROM, "WARNING: chd: Total GD-Rom frames is wrong: %u frames (549300 expected) in %zu tracks", total_frames, tracks.size()); + if (tracks.size() < 3) + throw FlycastException("Invalid CHD: less than 3 tracks"); FillGDSession(); + } else { type = CdRom_XA; diff --git a/core/imgread/gdi.cpp b/core/imgread/gdi.cpp index c8271ca4b..480e86942 100644 --- a/core/imgread/gdi.cpp +++ b/core/imgread/gdi.cpp @@ -158,6 +158,10 @@ Disc* load_gdi(const char* file, std::vector *digest) disc->tracks.push_back(t); } + if (disc->tracks.size() < 3) { + delete disc; + throw FlycastException("GDI parse error: less than 3 tracks"); + } disc->FillGDSession(); if (digest != nullptr) *digest = md5.getDigest();