websocket: fix bug where interleaved control frame breaks compression#3353
Open
staticglobal wants to merge 1 commit intotornadoweb:branch6.4from
Open
websocket: fix bug where interleaved control frame breaks compression#3353staticglobal wants to merge 1 commit intotornadoweb:branch6.4from
staticglobal wants to merge 1 commit intotornadoweb:branch6.4from
Conversation
Member
|
Thanks! The fix looks good. Is it feasible to add a test? I guess we don't have good test infrastructure for manipulating individual frames like this. I've used Autobahn (https://github.com/crossbario/autobahn-testsuite) for this before; I should revive that and get it in CI. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There is a bug in at least versions 6.4 and 6.3 and I assume going back further than that, but have not verified:
If tornado receives a control frame while in the middle of processing a compressed multi-fragment data message, it corrupts the final message.
Consider tornado receiving the following sequence of websocket frames:
0x2] [final:0] [compressed:1]0x0] [final:0]0] [final:1]0x0] [final:1]Background: the bit to indicate if a message is compressed only appears in the first frame. Tornado caches that flag in
self._frame_compressed, and then when it receives the final frame it consults that instance variable to determine if the payload should be decompressed. The issue here is that if a control frame is received in the interim, the value of its compressed bit is used to overwriteself._frame_compressedPer RFC7692:
So
self._frame_compressedwas initially set to1when receiving the initial frame, then set to0when the control frame arrived, so then when the final data frame arrives and is sent for processing, Tornado believes it does not need to be decompressed when in fact it does.This change does two things:
self._frame_compressedwhen receiving a control frameself._frame_compressedwhen processing a control frame. It should never need to be decompressed