protobuf-net / protobuf-net

Protocol Buffers library for idiomatic .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serializer.Deserialize can throw many unexpected exceptions

Metalnem opened this issue · comments

Serializer.Deserialize can throw many unexpected exceptions (IOException and ProtoException are expected in my opinion) when deserializing files from the attached archive. These are:

  • ArgumentException
  • IndexOutOfRangeException
  • InvalidOperationException
  • OverflowException

Here's the full program to reproduce this (args[0] should contain the path to one of the extracted files):

using System.IO;
using ProtoBuf;

namespace protobuf_net.Run
{
[ProtoContract]
  public class Person
  {
    [ProtoMember(1)] public int Id { get; set; }
    [ProtoMember(2)] public string Name { get; set; }
    [ProtoMember(3)] public Address Address { get; set; }
  }

  [ProtoContract]
  public class Address
  {
    [ProtoMember(1)] public string Line1 { get; set; }
    [ProtoMember(2)] public string Line2 { get; set; }
  }

  public class Program
  {
    public static void Main(string[] args)
    {
      using (var file = File.OpenRead(args[0]))
      {
        Serializer.Deserialize<Person>(file);
      }
    }
  }
}

Found via SharpFuzz.