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();