From 1d74321212e24b5709e20ca17710bc435882de45 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 23 Feb 2026 20:39:27 +0100 Subject: DiscIO: Move DecodeString to Volume.cpp This had to be in the header back when it was templated, but 083faa8b made it not templated. --- Source/Core/DiscIO/Volume.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'Source/Core/DiscIO/Volume.cpp') diff --git a/Source/Core/DiscIO/Volume.cpp b/Source/Core/DiscIO/Volume.cpp index 15ce4fe088..7ef63f6950 100644 --- a/Source/Core/DiscIO/Volume.cpp +++ b/Source/Core/DiscIO/Volume.cpp @@ -3,10 +3,12 @@ #include "DiscIO/Volume.h" +#include #include #include #include #include +#include #include #include #include @@ -34,6 +36,13 @@ const IOS::ES::TicketReader Volume::INVALID_TICKET{}; const IOS::ES::TMDReader Volume::INVALID_TMD{}; const std::vector Volume::INVALID_CERT_CHAIN{}; +std::string Volume::DecodeString(std::span data) const +{ + // strnlen to trim null bytes + std::string string(data.data(), strnlen(data.data(), data.size())); + return GetRegion() == Region::NTSC_J ? SHIFTJISToUTF8(string) : CP1252ToUTF8(string); +} + template static void AddToSyncHash(Common::SHA1::Context* context, const T& data) { -- cgit v1.2.3 From 7b372db5593ddc92dd442e57170f13072b43ade8 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Mon, 23 Feb 2026 20:59:46 +0100 Subject: DiscIO: Only allow alphanumeric ASCII in game IDs We often use game IDs in paths, so we should try to make sure path traversal is impossible in game IDs. Admittedly, doing any kind of real attack using the six bytes available in game IDs is unrealistic, but no game ID should contain non-alphanumeric or non-ASCII characters anyway. Might also fix https://bugs.dolphin-emu.org/issues/13982 by skipping converting between encodings for game IDs. --- Source/Core/DiscIO/Volume.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Source/Core/DiscIO/Volume.cpp') diff --git a/Source/Core/DiscIO/Volume.cpp b/Source/Core/DiscIO/Volume.cpp index 7ef63f6950..c1942b2aeb 100644 --- a/Source/Core/DiscIO/Volume.cpp +++ b/Source/Core/DiscIO/Volume.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,18 @@ std::string Volume::DecodeString(std::span data) const return GetRegion() == Region::NTSC_J ? SHIFTJISToUTF8(string) : CP1252ToUTF8(string); } +std::string Volume::FilterGameID(std::span data) +{ + std::string string(data.data(), data.size()); + + // We don't want game IDs to contain characters that are unprintable or might cause path + // traversal. Game IDs normally only contain ASCII uppercase letters and numbers, + // but GNHE5d contains a lowercase letter, so let's allow all ASCII letters and numbers. + std::ranges::replace_if(string, std::not_fn(Common::IsAlnum), '-'); + + return string; +} + template static void AddToSyncHash(Common::SHA1::Context* context, const T& data) { -- cgit v1.2.3