You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BinarySerializer seems to be swallowing some exceptions (at least IOException types) and just setting the current child object being deserialized to null without any indication of an error. As such, if we don't catch the error, the invalid data flows through the system. This is especially an issue with those objects where null could be a valid value (i.e. SerializeWhen case).
Reproduction:
.NET Core 3.1
class InsideTest
{
[FieldOrder(0)]
[SerializeAs(SerializedType.UInt1)]
public byte Value1 { get; set; }
[FieldOrder(1)]
[SerializeAs(SerializedType.UInt1)]
public byte Value2 { get; set; }
}
class Test
{
[FieldOrder(0)]
[SerializeAs(SerializedType.UInt1)]
public byte Value1 { get; set; }
[FieldOrder(1)]
public InsideTest Value2 { get; set; }
}
static void Main(string[] args)
{
var serializer = new BinarySerializer();
var testBytes = new byte[] {0x01, 0x02};
var testObject = serializer.Deserialize<Test>(testBytes);
// testObject.Value2 will be null, but no exception will be thrown as it will swallow the IOException
}
Visual Studio debugger sees that there was a System.IO.EndOfStreamException thrown from ValueValueNode.cs:600, but it gets caught in ObjectValueNode.cs:111 and current property/child value just gets set to null instead of rethrowing the exception.
If this behavior is intentional (Loose), is it possible to configure the serializer behavior to be Strict and throw on any deserialization error?
The text was updated successfully, but these errors were encountered:
Hello!
BinarySerializer seems to be swallowing some exceptions (at least IOException types) and just setting the current child object being deserialized to null without any indication of an error. As such, if we don't catch the error, the invalid data flows through the system. This is especially an issue with those objects where null could be a valid value (i.e. SerializeWhen case).
Reproduction:
.NET Core 3.1
Visual Studio debugger sees that there was a System.IO.EndOfStreamException thrown from ValueValueNode.cs:600, but it gets caught in ObjectValueNode.cs:111 and current property/child value just gets set to null instead of rethrowing the exception.
If this behavior is intentional (Loose), is it possible to configure the serializer behavior to be Strict and throw on any deserialization error?
The text was updated successfully, but these errors were encountered: