Skip to content

Commit

Permalink
Fixed potential infinite recursion ISyncSimple crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
SokyranTheDragon committed Feb 22, 2024
1 parent 84cc383 commit 5fa1ffc
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions Source/Client/Syncing/SyncSerialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ namespace Multiplayer.Client
{
public static class SyncSerialization
{
private static bool simplifiedSyncSimpleCheck = false;

public static void Init()
{
RwImplSerialization.Init();
Expand Down Expand Up @@ -52,10 +54,24 @@ public static bool CanHandle(SyncType syncType)
|| typeof(ITuple).IsAssignableFrom(gtd))
&& CanHandleGenericArgs(type);
if (typeof(ISyncSimple).IsAssignableFrom(type))
return ImplSerialization.syncSimples.
Where(t => type.IsAssignableFrom(t)).
SelectMany(AccessTools.GetDeclaredFields).
All(f => CanHandle(f.FieldType));
{
// Prevent infinite recursive calls to CanHandle on ISyncSimple subtypes.
if (simplifiedSyncSimpleCheck)
return true;

try
{
simplifiedSyncSimpleCheck = true;
return ImplSerialization.syncSimples.
Where(t => type.IsAssignableFrom(t)).
SelectMany(AccessTools.GetDeclaredFields).
All(f => CanHandle(f.FieldType));
}
finally
{
simplifiedSyncSimpleCheck = false;
}
}
if (typeof(Def).IsAssignableFrom(type))
return true;
if (typeof(Designator).IsAssignableFrom(type))
Expand Down

0 comments on commit 5fa1ffc

Please sign in to comment.