From 3dc76113283cbd734ca6f33ae64caaa688159480 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 15 Oct 2018 17:26:35 +0200 Subject: [PATCH] FileSys::Ticket::Load: Return error if signature type does not match (#4339) * FileSys::Ticket::Load: Return error if signature type does not match * fixup! FileSys::Ticket::Load: Return error if signature type does not match --- src/core/file_sys/cia_common.h | 2 +- src/core/file_sys/ticket.cpp | 3 +++ src/core/file_sys/title_metadata.cpp | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/file_sys/cia_common.h b/src/core/file_sys/cia_common.h index 900c82af6..6e02ac91b 100644 --- a/src/core/file_sys/cia_common.h +++ b/src/core/file_sys/cia_common.h @@ -33,7 +33,7 @@ inline u32 GetSignatureSize(u32 signature_type) { return 0x3C; } - UNREACHABLE(); + LOG_ERROR(Common_Filesystem, "Tried to read ticket with bad signature {}", signature_type); return 0; } diff --git a/src/core/file_sys/ticket.cpp b/src/core/file_sys/ticket.cpp index 1f41d0fb2..4a62b297b 100644 --- a/src/core/file_sys/ticket.cpp +++ b/src/core/file_sys/ticket.cpp @@ -22,6 +22,9 @@ Loader::ResultStatus Ticket::Load(const std::vector file_data, std::size_t o // Signature lengths are variable, and the body follows the signature u32 signature_size = GetSignatureSize(signature_type); + if (signature_size == 0) { + return Loader::ResultStatus::Error; + } // The ticket body start position is rounded to the nearest 0x40 after the signature std::size_t body_start = Common::AlignUp(signature_size + sizeof(u32), 0x40); diff --git a/src/core/file_sys/title_metadata.cpp b/src/core/file_sys/title_metadata.cpp index 21d973328..031b28b14 100644 --- a/src/core/file_sys/title_metadata.cpp +++ b/src/core/file_sys/title_metadata.cpp @@ -42,6 +42,9 @@ Loader::ResultStatus TitleMetadata::Load(const std::vector file_data, std::s // Signature lengths are variable, and the body follows the signature u32 signature_size = GetSignatureSize(signature_type); + if (signature_size == 0) { + return Loader::ResultStatus::Error; + } // The TMD body start position is rounded to the nearest 0x40 after the signature std::size_t body_start = Common::AlignUp(signature_size + sizeof(u32), 0x40); @@ -84,6 +87,9 @@ Loader::ResultStatus TitleMetadata::Save(const std::string& file_path) { // Signature lengths are variable, and the body follows the signature u32 signature_size = GetSignatureSize(signature_type); + if (signature_size == 0) { + return Loader::ResultStatus::Error; + } if (!file.WriteBytes(tmd_signature.data(), signature_size)) return Loader::ResultStatus::Error;