Skip to content

fix: The final frame can not be larger than the Frame Length #281

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 6 commits into from
Apr 1, 2020

Conversation

seebees
Copy link
Contributor

@seebees seebees commented Mar 26, 2020

The final frame content length is stored in the body header.
This means that while it should be related to the frame length in the header,
it is not required.

This enforces this requirement.
As well as adding a test and test vector for a zero length final frame.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Check any applicable:

  • Were any files moved? Moving files changes their URL, which breaks all hyperlinks to the files.

The final frame content length is stored in the body header.
This means that while it should be related to the frame length in the header,
it is not required.

This enforces this requirement.
As well as adding a test and test vector for a zero length final frame.
Copy link
Member

@mattsb42-aws mattsb42-aws left a comment

Choose a reason for hiding this comment

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

What about the serialize path?

@seebees
Copy link
Contributor Author

seebees commented Mar 27, 2020

@mattsb42-aws That is the edge of the edge.
But... I've been supper happy with all the small component testing in serialize so...

* In the case of the final frame,
* it MUST not be larger than the frame length.
*/
needs(frameLength === contentLength || (isFinalFrame && frameLength >= contentLength), 'Final frame length exceeds frame length.')
Copy link
Member

Choose a reason for hiding this comment

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

Strictly speaking, this should be two separate checks, no? If something goes terribly wrong on a non-final frame and I get an error that's talking about final frame length, I'm gonna be confused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps. What about the error message Content length exceeds frame length

Copy link
Member

@mattsb42-aws mattsb42-aws Mar 31, 2020

Choose a reason for hiding this comment

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

How about:

Suggested change
needs(frameLength === contentLength || (isFinalFrame && frameLength >= contentLength), 'Final frame length exceeds frame length.')
needs(frameLength === contentLength || isFinalFrame, 'Content length does not match frame length.')
needs(!isFinalFrame || frameLength >= contentLength, 'Final frame length exceeds frame length.')

Copy link
Member

Choose a reason for hiding this comment

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

Alternate suggestion:

Suggested change
needs(frameLength === contentLength || (isFinalFrame && frameLength >= contentLength), 'Final frame length exceeds frame length.')
if (isFinalFrame){
needs(frameLength >= contentLength, 'Final frame length exceeds frame length.')
}else{
needs(frameLength === contentLength, 'Content length does not match frame length.')
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Talking about this, having the exact values in question in the error message should resolve this.

Both the error message AND the condition should clearly express the intent.
Further, if this error is ever hit, knowing if you are a final frame or not will GREATLY simplify the debugging.

seebees added 2 commits April 1, 2020 14:21
Also, extent the check to the exact content length as long as we are here.
@seebees seebees merged commit 3dd6f43 into aws:master Apr 1, 2020
@seebees seebees deleted the final-frame-content-length branch April 1, 2020 23:27
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.

2 participants