DerrickBrayanClayton / protobuf-net

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

collections past certain length causes Argument Exception #100

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Please include an e-mail address if this might need a dialogue!
==============

What steps will reproduce the problem?
1. The following will cause a buffer overflow error in Helper.cs if the 
number of items exceed 32. 

[ProtoContract]
        public class TestClass
        {
            [ProtoMember(1)]
            public List<TestClass2> data = new List<TestClass2>();
        }

        [ProtoContract]
        public class TestClass2
        {
            [ProtoMember(1)]
            public Guid data1;

            [ProtoMember(2)]
            public Double data2;
        }

        [TestMethod]
        public void ProtoBufSerializeDeserializeGenericTemporalListTest2()
        {
            Random rand = new Random();

            TestClass test = new TestClass();
            for (int i = 0; i < 33; i++)
            {
                test.data.Add(new TestClass2 { data1 = Guid.NewGuid(), 
data2 = rand.NextDouble() });
            }

            using (MemoryStream ms = new MemoryStream())
            {
                Serializer.Serialize(ms, test);
                ms.Position = 0;

                TestClass dest = (TestClass)Serializer.Deserialize(ms, 
test.GetType());
            }
        }

2.
3.

What is the expected output? What do you see instead?
should not crash and work for lists of arbitrary length

What version of the product are you using? On what operating system?
latest snapsnot of the code

Please provide any additional information below.
can be reached @ savagepanda@gmail.com

Original issue reported on code.google.com by savagepa...@gmail.com on 16 Mar 2010 at 12:54

GoogleCodeExporter commented 8 years ago
That's odd - I've worked with some *much* bigger volumes than that. I'll look 
into 
this; can you clarify if this is v1 [the downloadable dll] or v2 [only 
available as 
source].

Original comment by marc.gravell on 16 Mar 2010 at 5:09

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
this is from the latest source code from svn this morning..

System.Buffer.BlockCopy(Array src, Int32 srcOffset, Array dst, Int32 dstOffset, 
Int32 count)
ProtoBuf.Helpers.BlockCopy(Byte[] from, Int32 fromIndex, Byte[] to, Int32 
toIndex, 
Int32 count) in Helpers.cs: line 103
ProtoBuf.ProtoWriter.EndSubItem(SubItemToken token, ProtoWriter writer, 
PrefixStyle 
style) in ProtoWriter.cs: line 230
ProtoBuf.ProtoWriter.EndSubItem(SubItemToken token, ProtoWriter writer) in 
ProtoWriter.cs: line 179
ProtoBuf.ProtoWriter.WriteObject(Object value, Int32 key, ProtoWriter writer) 
in 
ProtoWriter.cs: line 29
...

Not sure if it's related but i'm also encountering an Assert firing with the 
latest 
snapshot when trying to serialize a list i have. trace is here.

Helpers.DebugAssert(available <= count, "Asking for data without checking 
first");
in ProtoReader.cs 

    protobuf-net.dll!ProtoBuf.Helpers.DebugAssert(bool condition = false, string 
message = "Asking for data without checking first") Line 60 + 0xc bytes C#
>   protobuf-net.dll!ProtoBuf.ProtoReader.Ensure(int count = 8, bool strict = 
true) Line 142 + 0x1a bytes C#
    protobuf-net.dll!ProtoBuf.ProtoReader.SkipField() Line 496 + 0xf bytes  C#
    protobuf-net.dll!ProtoBuf.Serializers.TypeSerializer.Read(object value = 
{HyperCube.Generics.GenericSortedList<System.Guid,double>}, 
ProtoBuf.ProtoReader 
source = {ProtoBuf.ProtoReader}) Line 72 + 0xb bytes    C#
    protobuf-net.dll!ProtoBuf.Meta.RuntimeTypeModel.Deserialize(int key = 1, 
object value = {HyperCube.Generics.GenericSortedList<System.Guid,double>}, 
ProtoBuf.ProtoReader source = {ProtoBuf.ProtoReader}) Line 145 + 0xf bytes  C#
    protobuf-net.dll!ProtoBuf.ProtoReader.ReadObject(object value = 
{HyperCube.Generics.GenericSortedList<System.Guid,double>}, int key = 1, 
ProtoBuf.ProtoReader reader = {ProtoBuf.ProtoReader}) Line 374 + 0x1a bytes C#
    protobuf-net.dll!
ProtoBuf.Serializers.SubItemSerializer.ProtoBuf.Serializers.IProtoSerializer.Rea
d
(object value = {HyperCube.Generics.GenericSortedList<System.Guid,double>}, 
ProtoBuf.ProtoReader source = {ProtoBuf.ProtoReader}) Line 29 + 0x18 bytes  C#
    protobuf-net.dll!ProtoBuf.Serializers.TagDecorator.Read(object value = 
{HyperCube.Generics.GenericSortedList<System.Guid,double>}, 
ProtoBuf.ProtoReader 
source = {ProtoBuf.ProtoReader}) Line 41 + 0x18 bytes   C#

Btw, might as well attach this to the comment as well :)  The byte[] type added 
recently was giving me a problem until I changed the type from Variant to 
string.  I 
saw in the protobuffer specification that the byte type was grouped together 
with 
the string type?

Original comment by savagepa...@gmail.com on 16 Mar 2010 at 2:41

GoogleCodeExporter commented 8 years ago
The trunk is the *very* incomplete v2 - I'll add this to the unit tests and 
investigate, but I'm not concerned. The stable branch is v1. I'll add a note to 
clarify this.

You're absolutely right - BlobSerializer (in GetCoreSerializer) should have 
been 
"string" not "variant".

But again - if you want the stable branch, either use the download dll (on the 
homepage), or branches/v1.

Original comment by marc.gravell on 16 Mar 2010 at 4:30

GoogleCodeExporter commented 8 years ago
I should also add that the list (ListDecorator)/array (ArrayDecorator)/bytes 
(BlobSerializer) is all still very much in progress, and hasn't been tested 
against the 
v1 unit tests yet - arrays for example don't even have a sensible "read" 
implementation 
at this point. It is getting there, though.

Original comment by marc.gravell on 16 Mar 2010 at 4:36

GoogleCodeExporter commented 8 years ago

Original comment by marc.gravell on 22 Apr 2010 at 9:21