Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serializer.Deserialize hangs permanently #479

Closed
Metalnem opened this issue Dec 25, 2018 · 5 comments
Closed

Serializer.Deserialize hangs permanently #479

Metalnem opened this issue Dec 25, 2018 · 5 comments
Assignees
Labels

Comments

@Metalnem
Copy link

@Metalnem Metalnem commented Dec 25, 2018

Serializer.Deserialize method hangs permanently when trying to deserialize data from one small (16-byte) data stream. Here's the full program to reproduce it:

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)
    {
      var bytes = new byte[]
      {
        0xF2, 0xF2, 0xF2, 0x02,
        0xF2, 0xFF, 0xFF, 0xFF,
        0xFF, 0xF2, 0xF2, 0xF2,
        0xF2, 0x01, 0xF2, 0x00
      };

      using (var stream = new MemoryStream(bytes))
      {
        Serializer.Deserialize<Person>(stream);
      }
    }
  }
}

Found via SharpFuzz.

@mgravell
Copy link
Member

@mgravell mgravell commented Feb 18, 2019

Eek, well that's a major problem! Will investigate as a top priority. Sorry, this skipped past my radar when it came in originally - filtering is tricky, and it arrived on Christmas day...

@mgravell mgravell self-assigned this Feb 18, 2019
@mgravell mgravell added the bug label Feb 18, 2019
@AdamCaviness
Copy link

@AdamCaviness AdamCaviness commented Feb 26, 2021

We use protobuf-net (v2.4.6) for a local cache. We unfortunately cannot migrate to the 3.x version because we need AsReference and AsReferenceDefault support. I wanted to test how our client app would handle deserializing a corrupt protobuf-net cache file. I modified the protobuf-net file with a hex editor and found that as stated above Serializer.Deserialize hangs permanently and I don't know how to work around it. I have the call to Serializer.Deserialize() in a try/catch. Thank you for the excellent library!

@mgravell
Copy link
Member

@mgravell mgravell commented Feb 26, 2021

@AdamCaviness
Copy link

@AdamCaviness AdamCaviness commented Mar 1, 2021

@mgravell I found my own asinine mistake, sorry. There is no hang in my case at all. The subsequent breakpoint was not hit due to over-freezing threads while debugging.

@mgravell
Copy link
Member

@mgravell mgravell commented Mar 1, 2021

Ok. In that case, closing out unless you still think there is a problem.

@mgravell mgravell closed this Mar 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants