Skip to content

fix issues caused by websocket frame fragmentation#1962

Merged
fafhrd91 merged 1 commit intoaio-libs:masterfrom
pjknkda:master
Jun 8, 2017
Merged

fix issues caused by websocket frame fragmentation#1962
fafhrd91 merged 1 commit intoaio-libs:masterfrom
pjknkda:master

Conversation

@pjknkda
Copy link
Copy Markdown
Contributor

@pjknkda pjknkda commented Jun 6, 2017

What do these changes do?

This MR fixes issues caused by websocket frame fragmentation.

Based on autobahn-testsuite, there were several bugs in websocket implementation which is mainly caused by wrong handling of fragmented frames.

The rationale of deleting the test case "test_parse_frame_header_continuation" is that according to RFC6455 Section 5.5, control frames can be injected in the middle of a fragmented message and therefore we cannot reject the frame only seeing the "FIN" flag of the last frame. Also, test for invalid continuation frame without preceding text/binary frame is done by test case "test_unknown_frame".

Here is the report generated from autobahn-testsuite.

Related issue number

#1845, #1951

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new entry to CHANGES.rst
    • Choose any open position to avoid merge conflicts with other PRs.
    • Add a link to the issue you are fixing (if any) using #issue_number format at the end of changelog message. Use Pull Request number if there are no issues for PR or PR covers the issue only partially.

@pjknkda pjknkda changed the title fix issues caused by websocket fragmentation fix issues caused by websocket frame fragmentation Jun 6, 2017
@codecov-io
Copy link
Copy Markdown

codecov-io commented Jun 6, 2017

Codecov Report

Merging #1962 into master will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1962      +/-   ##
==========================================
+ Coverage   97.05%   97.08%   +0.02%     
==========================================
  Files          37       37              
  Lines        7612     7609       -3     
  Branches     1328     1327       -1     
==========================================
- Hits         7388     7387       -1     
+ Misses        101      100       -1     
+ Partials      123      122       -1
Impacted Files Coverage Δ
aiohttp/http_websocket.py 98.74% <100%> (+0.6%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6a902ff...03984c2. Read the comment docs.

Copy link
Copy Markdown
Member

@asvetlov asvetlov left a comment

Choose a reason for hiding this comment

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

The PR is good after fixing minor notes.
@fafhrd91 ?

CHANGES.rst Outdated
-

-
- Fix websocket issues caused by frame fragmentation.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add #1962 at the end of line

if self._state == WSParserState.READ_HEADER:
if buf_length - start_pos >= 2:
data = buf[start_pos:start_pos+2]
data = buf[start_pos:start_pos + 2]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please don't touch what is not broken: spaces are not required here.

if length == 126:
if buf_length - start_pos >= 2:
data = buf[start_pos:start_pos+2]
data = buf[start_pos:start_pos + 2]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

spaces

elif length > 126:
if buf_length - start_pos >= 8:
data = buf[start_pos:start_pos+8]
data = buf[start_pos:start_pos + 8]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

spaces

if self._state == WSParserState.READ_PAYLOAD_MASK:
if buf_length - start_pos >= 4:
self._frame_mask = buf[start_pos:start_pos+4]
self._frame_mask = buf[start_pos:start_pos + 4]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

spaces

else:
self._payload_length = 0
payload.extend(buf[start_pos:start_pos+length])
payload.extend(buf[start_pos:start_pos + length])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

spaces

@pjknkda
Copy link
Copy Markdown
Contributor Author

pjknkda commented Jun 7, 2017

@asvetlov I've fixed the commit according to your comments. Thank you for reviewing!

@fafhrd91
Copy link
Copy Markdown
Member

fafhrd91 commented Jun 7, 2017

Lgtm

@fafhrd91
Copy link
Copy Markdown
Member

fafhrd91 commented Jun 7, 2017

@asvetlov ping

@fafhrd91
Copy link
Copy Markdown
Member

fafhrd91 commented Jun 7, 2017

@pjknkda btw did you run autobahn test suit against your fix?

@pjknkda
Copy link
Copy Markdown
Contributor Author

pjknkda commented Jun 8, 2017

@fafhrd91 Yes I did. The second test report (this) is the result against my fix.

@fafhrd91
Copy link
Copy Markdown
Member

fafhrd91 commented Jun 8, 2017

Awesome! Thanks

@fafhrd91 fafhrd91 merged commit 6b85bcd into aio-libs:master Jun 8, 2017
@lock
Copy link
Copy Markdown

lock bot commented Oct 28, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 28, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants