anerjan / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
Other
0 stars 0 forks source link

Protobuf v2 beta 2 False-positive recursion error #178

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
From: 
http://stackoverflow.com/questions/6174298/protobuf-v2-beta-2-false-positive-rec
ursion-error

Hello,

I'm getting a **ProtoBuf.ProtoException : Possible recursion detected** while 
serializing a simple tree.

Tree code:

    [ProtoContract]
    [ProtoInclude(10, typeof(BinaryNode))]
    public class Node
    {
    }

    [ProtoContract]
    public class BinaryNode : Node
    {
        [ProtoMember(1, IsRequired = true)] public Node Left { get; set; }
        [ProtoMember(2, IsRequired = true)] public Node Right { get; set; }
    }

Serialization code:

    BinaryNode head = new BinaryNode();
    BinaryNode node = head;
    // 13 is the magic limit that triggers recursion check        
    for (int i = 0; i < 13; ++i)
    {
        node.Left = new BinaryNode();
        node = (BinaryNode)node.Left;
    }

    Serializer.Serialize(new MemoryStream(), head);

Please note that I'm new to protobuf, so I'm maybe missing something obvious :-)

Original issue reported on code.google.com by marc.gravell on 30 May 2011 at 9:12

GoogleCodeExporter commented 9 years ago
Fixed in r399

Original comment by marc.gravell on 30 May 2011 at 9:49