MessageParser.ParseFrom should throw InvalidProtocolBufferException when parsing invalid message, but it can also throw several other unexpected exceptions:
The following C# program demonstrates this:
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) { } } } }
Proto definition of the Person class:
syntax = "proto3"; package sample; message Person { string name = 1; int32 id = 2; string email = 3; enum PhoneType { MOBILE = 0; HOME = 1; WORK = 2; } message PhoneNumber { string number = 1; PhoneType type = 2; } repeated PhoneNumber phones = 4; }
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.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4