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

String length serialization bug #21

Closed
TechInterMezzo opened this issue Mar 31, 2016 · 2 comments
Closed

String length serialization bug #21

TechInterMezzo opened this issue Mar 31, 2016 · 2 comments
Labels

Comments

@TechInterMezzo
Copy link

There is a bug in the string serialization code. For strings longer than 254 bytes you write a marker with a value of 254. Shouldn't it be 255? Also you add 1 to the length before writing it to the stream and subtract 1 after reading the length from the stream (source). I don't know why you did this in the first place, but this also collides with the marker and produces some bugs for me.

@rogeralsing
Copy link
Collaborator

You are correct.
I have fixed this in the dotnet core dev branch:

https://github.com/rogeralsing/Wire/blob/dotnetcore/Wire/ValueSerializers/StringSerializer.cs

Regarding the +1 -1 length.

0 = null
1 = 0 length
2 = 1 length 
etc..
255 = marker for long string

I have a test that verifies length per length

            for (int i = 0; i < 2000; i++)
            {
                var str = new string('a',i);
                SerializeAndAssert(str);
            }

The updated code now passes this test.

@TechInterMezzo
Copy link
Author

Thank you for the fix and explanation. Your serializer is really useful for my simple ipc library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants