diff options
| author | Dentomologist <dentomologist@gmail.com> | 2026-02-26 14:07:27 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-26 14:07:27 -0800 |
| commit | 65f0dc9b2ecb08bec356f0ce931702900ba54acb (patch) | |
| tree | 036109820f66d8dc2e6cbf8ff56aad70ba020a72 /Source/Core/DiscIO/Volume.cpp | |
| parent | 2a3078b833fe3d7b199b833fb4dfc08111d44dd7 (diff) | |
| parent | 7b372db5593ddc92dd442e57170f13072b43ade8 (diff) | |
Merge pull request #14416 from JosJuice/game-id-ascii
DiscIO: Only allow alphanumeric ASCII in game IDs
Diffstat (limited to 'Source/Core/DiscIO/Volume.cpp')
| -rw-r--r-- | Source/Core/DiscIO/Volume.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Source/Core/DiscIO/Volume.cpp b/Source/Core/DiscIO/Volume.cpp index 15ce4fe088..c1942b2aeb 100644 --- a/Source/Core/DiscIO/Volume.cpp +++ b/Source/Core/DiscIO/Volume.cpp @@ -3,10 +3,13 @@ #include "DiscIO/Volume.h" +#include <cstring> #include <functional> #include <map> #include <memory> #include <optional> +#include <ranges> +#include <span> #include <string> #include <type_traits> #include <utility> @@ -34,6 +37,25 @@ const IOS::ES::TicketReader Volume::INVALID_TICKET{}; const IOS::ES::TMDReader Volume::INVALID_TMD{}; const std::vector<u8> Volume::INVALID_CERT_CHAIN{}; +std::string Volume::DecodeString(std::span<const char> 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); +} + +std::string Volume::FilterGameID(std::span<const char> 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 <typename T> static void AddToSyncHash(Common::SHA1::Context* context, const T& data) { |
