Skip to content

[3.15] gh-150751: validate http.client Content-Length and chunk-size (GH-150752) - #159021

Draft
miss-islington wants to merge 3 commits into
python:3.15from
miss-islington:backport-2eb2af8-3.15
Draft

miss-islington wants to merge 3 commits into
python:3.15from
miss-islington:backport-2eb2af8-3.15

Conversation

@miss-islington

@miss-islington miss-islington commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

RFC 9112 defines Content-Length as 1DIGIT and chunk-size as 1HEXDIG, but int() also accepts a sign, underscores, surrounding whitespace and an 0x prefix, so malformed framing values were parsed instead of rejected.
(cherry picked from commit 2eb2af8)

Co-authored-by: metsw24-max metsw24@gmail.com

…ythonGH-150752)

RFC 9112 defines Content-Length as 1*DIGIT and chunk-size as 1*HEXDIG, but int() also accepts a sign, underscores, surrounding whitespace and an 0x prefix, so malformed framing values were parsed instead of rejected.
(cherry picked from commit 2eb2af8)

Co-authored-by: metsw24-max <metsw24@gmail.com>
danilablagorodniy37 and others added 2 commits November 6, 2026 14:04
…http.client (pythonGH-159156)

pythongh-150752 started validating the Content-Length value against the
RFC 9112 grammar (1*DIGIT), but the compat32 header parser keeps
trailing SP/HTAB in the field value, so "Content-Length: 5 " is now
treated as a missing header. HTTPResponse then assumes that the
connection will close and read() blocks until the server closes it,
which never happens on a keep-alive connection.

RFC 9112, section 5.1 says that optional whitespace around a field
value is excluded by parsers. Strip SP/HTAB before the grammar check;
values such as "+5", "5_0" and "5 0" are still rejected.
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.

4 participants