Skip to content

Fix MessagePackReader for multi-segment strings #1

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

Merged
merged 3 commits into from
Apr 17, 2019

Conversation

SteveSandersonMS
Copy link
Member

This fixes an issue reported in server-side Blazor whereby it would sometimes abort connections when the server was under high traffic: dotnet/aspnetcore#6385. The SignalR hub was receiving corrupted messages, e.g., to invoke a hub method called OnOnOnOnOnOnOnOnO (should be OnRenderCompleted).

The bug is that MessagePackReader has two ways of reading strings: fast path (used when the sequence reader contains only one span), and slow path (used when it has multiple spans), but only the fast path actually works. The slow path code will always produce corrupted results, because it doesn't advance the reader each time it gets some bytes from it.

AFAICT there were no tests for MessagePackReader's string handling, so I've added a couple of basic ones. However it's not my goal to create a complete test suite for MessagePackReader in this PR, of course!


var reader = new MessagePackReader(seq);
var result = reader.ReadString();
Assert.Equal("AB", result);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the fix, this assertion fails, because result equals "AA" instead of "AB".

@BrennanConroy
Copy link
Member

cc @AArnott

@AArnott
Copy link

AArnott commented Apr 17, 2019

If you could rebase your 3 commits onto f2dc12b^ (i.e. such that they do not include f2dc12b) then I'd be very happy to merge your commits into my master branch.

The trouble with f2dc12b is that it is not yet in my master branch and is unrelated to this change.

@pranavkm pranavkm merged commit 1917b80 into master Apr 17, 2019
@pranavkm
Copy link

@AArnott I'll get this upstream next week. Merging this in so we can update this for the preview5 release.

@pranavkm pranavkm deleted the stevesa/fix-readstringslow branch April 17, 2019 16:21
pranavkm pushed a commit that referenced this pull request Apr 23, 2019
* Add failing unit test to show the bug
pranavkm pushed a commit that referenced this pull request Apr 23, 2019
* Add failing unit test to show the bug
pranavkm pushed a commit that referenced this pull request Apr 25, 2019
* Add failing unit test to show the bug
dougbu pushed a commit that referenced this pull request Aug 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants