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:
parent
239dc7dffb
commit
c7354d9c41
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user