From be8e93f472ba8630622dd71a5b50a065ca942977 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Sun, 16 Jul 2017 14:52:17 +0200 Subject: [PATCH] Ensure that Volume::GetRegion doesn't return invalid enum values --- Source/Core/DiscIO/VolumeGC.cpp | 5 ++++- Source/Core/DiscIO/VolumeWii.cpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/Core/DiscIO/VolumeGC.cpp b/Source/Core/DiscIO/VolumeGC.cpp index dd13ecdcd0..46ac57278c 100644 --- a/Source/Core/DiscIO/VolumeGC.cpp +++ b/Source/Core/DiscIO/VolumeGC.cpp @@ -61,7 +61,10 @@ std::string VolumeGC::GetGameID(const Partition& partition) const Region VolumeGC::GetRegion() const { const std::optional region_code = ReadSwapped(0x458, PARTITION_NONE); - return region_code ? static_cast(*region_code) : Region::UNKNOWN_REGION; + if (!region_code) + return Region::UNKNOWN_REGION; + const Region region = static_cast(*region_code); + return region <= Region::PAL ? region : Region::UNKNOWN_REGION; } Country VolumeGC::GetCountry(const Partition& partition) const diff --git a/Source/Core/DiscIO/VolumeWii.cpp b/Source/Core/DiscIO/VolumeWii.cpp index cf570e39ea..7225a1e57f 100644 --- a/Source/Core/DiscIO/VolumeWii.cpp +++ b/Source/Core/DiscIO/VolumeWii.cpp @@ -233,7 +233,10 @@ std::string VolumeWii::GetGameID(const Partition& partition) const Region VolumeWii::GetRegion() const { const std::optional region_code = m_pReader->ReadSwapped(0x4E000); - return region_code ? static_cast(*region_code) : Region::UNKNOWN_REGION; + if (!region_code) + return Region::UNKNOWN_REGION; + const Region region = static_cast(*region_code); + return region <= Region::NTSC_K ? region : Region::UNKNOWN_REGION; } Country VolumeWii::GetCountry(const Partition& partition) const