using System;
using Sample;
namespace Google.Protobuf.Run
{
public class Program
{
public static void Main(string[] args)
{
try
{
var bytes = new byte[]
{
34, 255, 255, 255, 255,
7, 34, 255, 255, 101
};
Person.Parser.ParseFrom(bytes);
}
catch (ArgumentException) { }
try
{
var bytes = new byte[]
{
10, 247, 181, 144, 151, 110, 32, 68,
111, 101, 16, 210, 9, 26, 16, 106, 100,
111, 101, 64, 101, 120, 97, 109, 112,
108, 101, 46, 99, 111, 109, 34, 12, 10,
8, 53, 53, 53, 45, 52, 51, 50, 49, 16, 1
};
Person.Parser.ParseFrom(bytes);
}
catch (ArgumentOutOfRangeException) { }
try
{
var bytes = new byte[]
{
14, 8, 74, 111, 104, 110, 32, 68, 111,
101, 16, 210, 9, 26, 16, 106, 100, 111,
101, 64, 101, 120, 97, 109, 112, 108,
101, 46, 99, 111, 109, 34, 12, 10, 8, 53,
53, 53, 45, 52, 51, 50, 59, 16, 1
};
Person.Parser.ParseFrom(bytes);
}
catch (InvalidOperationException) { }
}
}
}
MessageParser.ParseFrom should throw InvalidProtocolBufferException when parsing invalid message, but it can also throw several other unexpected exceptions:
The following C# program demonstrates this:
Proto definition of the Person class:
Generated C# code for the Person class is in the attached archive.
I'm using .NET Core 2.1 and the latest NuGet version of the Google.Protobuf package (version 3.6.1).
Found via SharpFuzz.