Skip to content

Commit

Permalink
Apply type inheritance check
Browse files Browse the repository at this point in the history
  • Loading branch information
minisbett authored and bdach committed Dec 19, 2024
1 parent 239dc7d commit c7354d9
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions osu.Game/IO/Serialization/Converters/TypedListConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,12 @@ public override IReadOnlyList<T> ReadJson(JsonReader reader, Type objectType, IR
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);
Expand Down

0 comments on commit c7354d9

Please sign in to comment.