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.
This commit is contained in:
JosJuice
2026-02-23 20:59:46 +01:00
parent 1d74321212
commit 7b372db559
6 changed files with 24 additions and 10 deletions

View File

@@ -8,6 +8,7 @@
#include <map>
#include <memory>
#include <optional>
#include <ranges>
#include <span>
#include <string>
#include <type_traits>
@@ -43,6 +44,18 @@ std::string Volume::DecodeString(std::span<const char> data) const
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)
{