Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

[release/2.1] Fix WebSocket server split header parsing with large payload (#30402)#30407

Merged
stephentoub merged 1 commit intodotnet:release/2.1from
stephentoub:port30402
Jun 26, 2018
Merged

[release/2.1] Fix WebSocket server split header parsing with large payload (#30402)#30407
stephentoub merged 1 commit intodotnet:release/2.1from
stephentoub:port30402

Conversation

@stephentoub
Copy link
Member

Port #30402 to release/2.1
Fixes #30375

…#30402)

* Refactor WebSocket{Protocol}.CreateFromStream tests to be shared

We have the WebSocket.CreateFromStream and WebSocketProtocol.CreateFromStream methods, which are identical, except that the former is netcoreapp-only and the latter is in a separate NuGet package for downlevel use.  However, tests for them were separate, with some tests only for one and some tests for the other.

This commit centralizes those tests so they're shared by and apply to both methods.  There are no code changes to the actual bodies of tests, just moving code around to have it apply to both.

* Fix WebSocket server split header parsing with large payload

When ReceiveAsync is called, as a fast path it checks to see whether there's already enough data in the buffer to satisfy any possible header, skipping subsequent checks if there is.  The max header size differs between client and server, though.  The maximum size header a client can send to the server is 14 bytes, which includes a 4-byte masking value; the maximum size header a server can send to a client is 10 bytes, as it doesn't include a masking value.  However, the code currently has those values reversed.  If the code is running on the client, this means that we end up falling back to the slow-path unnecessarily if there are 10, 11, 12, or 13 bytes already in the buffer when ReceiveAsync is called.  However, on the server, this means we end up potentially throwing an exception or misinterpreting the payload if 10, 11, 12, or 13 bytes are in the buffer and the packet contains a large payload (in which case it'll be using an 8-byte length and be the full 14 byte header), as we'll end up erroneously taking the fast path when we should have taken the slow path to read more data from the network.

The fix is simply to swap the branches of the conditional.

* Address PR feedback
@stephentoub stephentoub added Servicing-consider Issue for next servicing release review area-System.Net labels Jun 15, 2018
@davidsh davidsh added this to the 2.1.x milestone Jun 15, 2018
@stephentoub stephentoub merged commit c6f4eb6 into dotnet:release/2.1 Jun 26, 2018
@stephentoub stephentoub deleted the port30402 branch June 26, 2018 22:45
@danmoseley danmoseley removed the Servicing-consider Issue for next servicing release review label Aug 17, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants