From e2c56668834fdef28d3ffb429fc5a569b8452ad7 Mon Sep 17 00:00:00 2001 From: Valentin Vanelslande Date: Sat, 24 Mar 2018 13:06:50 -0600 Subject: [PATCH] Service/AM: Fix crash when scanning titles with installed titles with invalid title IDs (#3542) * Service/AM: Fix crash when scanning titles with installed titles with invalid title IDs Fixes #3332 --- src/core/hle/service/am/am.cpp | 11 +++++++---- src/core/hle/service/am/am.h | 5 ++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 031b295b7..40600e34e 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -456,11 +456,14 @@ void Module::ScanForTitles(Service::FS::MediaType media_type) { for (const FileUtil::FSTEntry& tid_high : entries.children) { for (const FileUtil::FSTEntry& tid_low : tid_high.children) { std::string tid_string = tid_high.virtualName + tid_low.virtualName; - u64 tid = std::stoull(tid_string.c_str(), nullptr, 16); - FileSys::NCCHContainer container(GetTitleContentPath(media_type, tid)); - if (container.Load() == Loader::ResultStatus::Success) - am_title_list[static_cast(media_type)].push_back(tid); + if (tid_string.length() == TITLE_ID_VALID_LENGTH) { + u64 tid = std::stoull(tid_string.c_str(), nullptr, 16); + + FileSys::NCCHContainer container(GetTitleContentPath(media_type, tid)); + if (container.Load() == Loader::ResultStatus::Success) + am_title_list[static_cast(media_type)].push_back(tid); + } } } } diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index 220ca3f23..cc322375a 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -52,7 +52,10 @@ enum class InstallStatus : u32 { ErrorEncrypted, }; -// Progress callback for InstallCIA, recieves bytes written and total bytes +// Title ID valid length +constexpr size_t TITLE_ID_VALID_LENGTH = 16; + +// Progress callback for InstallCIA, receives bytes written and total bytes using ProgressCallback = void(size_t, size_t); // A file handled returned for CIAs to be written into and subsequently installed.