fix(core): Fixes ability to delete object type if it deserialized improperly (#475)

This commit is contained in:
Kamron Batman 2021-02-06 21:03:47 -08:00 committed by GitHub
parent 8d8a1b63bd
commit bd87035f12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -329,15 +329,31 @@ namespace Server
}
bin.Read(buffer.AsSpan());
string error;
t.Deserialize(br);
if (br.Position != entry.Length)
try
{
WriteConsoleLine($"***** Bad deserialize on {t.GetType()} *****");
WriteConsoleLine(
$"Serialized object was {entry.Length} bytes, but {br.Position} bytes deserialized"
);
t.Deserialize(br);
error = br.Position != entry.Length
? $"Serialized object was {entry.Length} bytes, but {br.Position} bytes deserialized"
: null;
}
catch (Exception e)
{
error = e.ToString();
}
if (error == null)
{
t.InitializeSaveBuffer(buffer);
}
else
{
Utility.PushColor(ConsoleColor.Red);
WriteConsoleLine($"***** Bad deserialize of {t.GetType()} *****");
WriteConsoleLine(error);
Utility.PopColor();
WriteConsoleLine("Delete the object and continue? (y/n)");
@ -347,10 +363,6 @@ namespace Server
}
t.Delete();
}
else
{
t.InitializeSaveBuffer(buffer);
}
}
}