Repository navigation
Parse chunk size strictly in Response.parse - #1780
Closed
Bountybette wants to merge 1 commit into
Closed
Bountybette wants to merge 1 commit into
Bountybette wants to merge 1 commit into
Conversation
Also raise ValueError instead of AssertionError for negative values.
Member
|
Checklist? |
Member
|
As it stands this PR comes across as "AI found something that doesn't happen in real life and creates unnecessary work for maintainers". |
Member
|
Fixed in bc17da4 with less code + also covering the parsing of the HTTP status code. |
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.
Checklist
Problem
Follow-up to 0437fbc, which made Content-Length strict.
read_bodystill parses the chunk-size line withint(raw_chunk_size, 16), so+5,0x5,0_5and padded values are accepted, and-1reachesStreamReader.read_exactand fails itsassert n >= 0with a bare AssertionError (underpython -O,read_exact(-1)instead returns everything buffered except the last byte). A server sending a malformed chunked error response triggers this. It is a strictness issue, not a vulnerability: the body is only read for display and the connection is not reused.Solution
Validate the chunk size against
1*HEXDIG(RFC 9112 section 7.1) before converting it and raise ValueError, like the Content-Length fix. Trailing BWS before;is stripped so valid chunk extensions such as6 ;foo=barkeep working. An alternative was rejecting negatives only afterint(), but that would still accept0xand_forms.