1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-18 10:43:22 +08:00

Apply type inheritance check

This commit is contained in:
mini 2024-12-15 17:31:13 +01:00 committed by Bartłomiej Dach
parent 239dc7dffb
commit c7354d9c41
No known key found for this signature in database

View File

@ -62,8 +62,12 @@ namespace osu.Game.IO.Serialization.Converters
if (tok["$type"] == null)
throw new JsonException("Expected $type token.");
string typeName = lookupTable[(int)tok["$type"]];
var instance = (T)Activator.CreateInstance(Type.GetType(typeName).AsNonNull())!;
// Prevent instantiation of types that do not inherit the type targetted by this converter
Type type = Type.GetType(lookupTable[(int)tok["$type"]]).AsNonNull();
if (!type.IsAssignableTo(typeof(T)))
continue;
var instance = (T)Activator.CreateInstance(type)!;
serializer.Populate(itemReader, instance);
list.Add(instance);