Merge pull request #8622 from JosJuice/volumeverifier-invalid-partition-biggest-offset

VolumeVerifier: Ignore invalid partitions in GetBiggestReferencedOffset
This commit is contained in:
Tilka 2020-02-10 00:31:49 +00:00 committed by GitHub
commit c598772052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 17 deletions

View File

@ -391,27 +391,29 @@ void VolumeVerifier::Start()
(m_volume.GetVolumeType() == Platform::WiiDisc && !m_volume.IsEncryptedAndHashed()) || (m_volume.GetVolumeType() == Platform::WiiDisc && !m_volume.IsEncryptedAndHashed()) ||
IsDebugSigned(); IsDebugSigned();
CheckPartitions();
if (m_volume.GetVolumeType() == Platform::WiiWAD) if (m_volume.GetVolumeType() == Platform::WiiWAD)
CheckCorrectlySigned(PARTITION_NONE, Common::GetStringT("This title is not correctly signed.")); CheckCorrectlySigned(PARTITION_NONE, Common::GetStringT("This title is not correctly signed."));
CheckDiscSize(); CheckDiscSize(CheckPartitions());
CheckMisc(); CheckMisc();
SetUpHashing(); SetUpHashing();
} }
void VolumeVerifier::CheckPartitions() std::vector<Partition> VolumeVerifier::CheckPartitions()
{ {
if (m_volume.GetVolumeType() == Platform::WiiWAD)
return {};
const std::vector<Partition> partitions = m_volume.GetPartitions(); const std::vector<Partition> partitions = m_volume.GetPartitions();
if (partitions.empty()) if (partitions.empty())
{ {
if (m_volume.GetVolumeType() != Platform::WiiWAD && if (!m_volume.GetFileSystem(m_volume.GetGamePartition()))
!m_volume.GetFileSystem(m_volume.GetGamePartition()))
{ {
AddProblem(Severity::High, AddProblem(Severity::High,
Common::GetStringT("The filesystem is invalid or could not be read.")); Common::GetStringT("The filesystem is invalid or could not be read."));
return {};
} }
return; return {m_volume.GetGamePartition()};
} }
std::optional<u32> partitions_in_first_table = m_volume.ReadSwapped<u32>(0x40000, PARTITION_NONE); std::optional<u32> partitions_in_first_table = m_volume.ReadSwapped<u32>(0x40000, PARTITION_NONE);
@ -484,8 +486,14 @@ void VolumeVerifier::CheckPartitions()
} }
} }
std::vector<Partition> valid_partitions;
for (const Partition& partition : partitions) for (const Partition& partition : partitions)
CheckPartition(partition); {
if (CheckPartition(partition))
valid_partitions.push_back(partition);
}
return valid_partitions;
} }
bool VolumeVerifier::CheckPartition(const Partition& partition) bool VolumeVerifier::CheckPartition(const Partition& partition)
@ -720,12 +728,12 @@ bool VolumeVerifier::ShouldBeDualLayer() const
std::string_view(m_volume.GetGameID())); std::string_view(m_volume.GetGameID()));
} }
void VolumeVerifier::CheckDiscSize() void VolumeVerifier::CheckDiscSize(const std::vector<Partition>& partitions)
{ {
if (!IsDisc(m_volume.GetVolumeType())) if (!IsDisc(m_volume.GetVolumeType()))
return; return;
m_biggest_referenced_offset = GetBiggestReferencedOffset(); m_biggest_referenced_offset = GetBiggestReferencedOffset(partitions);
if (ShouldBeDualLayer() && m_biggest_referenced_offset <= SL_DVD_R_SIZE) if (ShouldBeDualLayer() && m_biggest_referenced_offset <= SL_DVD_R_SIZE)
{ {
AddProblem(Severity::Medium, AddProblem(Severity::Medium,
@ -781,12 +789,8 @@ void VolumeVerifier::CheckDiscSize()
} }
} }
u64 VolumeVerifier::GetBiggestReferencedOffset() const u64 VolumeVerifier::GetBiggestReferencedOffset(const std::vector<Partition>& partitions) const
{ {
std::vector<Partition> partitions = m_volume.GetPartitions();
if (partitions.empty())
partitions.emplace_back(m_volume.GetGamePartition());
const u64 disc_header_size = m_volume.GetVolumeType() == Platform::GameCubeDisc ? 0x460 : 0x50000; const u64 disc_header_size = m_volume.GetVolumeType() == Platform::GameCubeDisc ? 0x460 : 0x50000;
u64 biggest_offset = disc_header_size; u64 biggest_offset = disc_header_size;
for (const Partition& partition : partitions) for (const Partition& partition : partitions)

View File

@ -145,7 +145,7 @@ private:
u64 block_index; u64 block_index;
}; };
void CheckPartitions(); std::vector<Partition> CheckPartitions();
bool CheckPartition(const Partition& partition); // Returns false if partition should be ignored bool CheckPartition(const Partition& partition); // Returns false if partition should be ignored
std::string GetPartitionName(std::optional<u32> type) const; std::string GetPartitionName(std::optional<u32> type) const;
void CheckCorrectlySigned(const Partition& partition, std::string error_text); void CheckCorrectlySigned(const Partition& partition, std::string error_text);
@ -154,8 +154,8 @@ private:
bool ShouldHaveInstallPartition() const; bool ShouldHaveInstallPartition() const;
bool ShouldHaveMasterpiecePartitions() const; bool ShouldHaveMasterpiecePartitions() const;
bool ShouldBeDualLayer() const; bool ShouldBeDualLayer() const;
void CheckDiscSize(); void CheckDiscSize(const std::vector<Partition>& partitions);
u64 GetBiggestReferencedOffset() const; u64 GetBiggestReferencedOffset(const std::vector<Partition>& partitions) const;
u64 GetBiggestReferencedOffset(const FileInfo& file_info) const; u64 GetBiggestReferencedOffset(const FileInfo& file_info) const;
void CheckMisc(); void CheckMisc();
void CheckSuperPaperMario(); void CheckSuperPaperMario();