Repository navigation
Conversation
A declared content-length was only checked when DATA frames arrived. END_STREAM on the header block, or on a trailers block, skipped the check, so a request or response could declare five bytes and send none. Validate the zero-length body on both paths; trailers also no longer reset the expected length.
Member
|
How does this PR related to your other PR #1329? |
Author
|
Thanks for asking — they do overlap on one path and I should have said so in the description.
So as written this branch is a superset on the trailers side and adds the header-block side. Two clean shapes, and it is your call:
I would lean to 1, since #1329 has already been reviewed on its own terms and would have to be re-read otherwise. I will not push anything here until you say which you prefer. |
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.
What is wrong
content-lengthwas only enforced when a DATA frame arrived. IfEND_STREAMwas on the HEADERS block, or on a trailers block, the zero-length body skipped_track_content_length(), so a message could declarecontent-length: 5and send no body at all. A trailers block containing its owncontent-lengthalso overwrote the expected length from the header block.What changes
_initialize_content_length(); content-length belongs to the header block.END_STREAMarrives on a header or trailers block, the zero-length body is validated against the expected length. HEAD, 204 and 304 keep their zero-length exemption from_initialize_content_length().Tests
tests/test_content_length_end_stream.pycovers a request with END_STREAM on trailers, the same request with the declared body then trailers, a response with END_STREAM on HEADERS, and a response with no content-length. The two rejection cases fail on the parent revision; the full h2 suite is 1666 passed.ruff check src/andmypy --strict src/h2/stream.pypass.