Skip to content

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

Merged
encukou merged 3 commits into
python:3.14from
miss-islington:backport-2eb2af8-3.14
Nov 18, 2026
Merged

encukou merged 3 commits into
python:3.14from
miss-islington:backport-2eb2af8-3.14

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 13:34
…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.
@encukou encukou added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 16, 2026
@bedevere-bot

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @encukou for commit 10329dc 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F159020%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Nov 16, 2026
@encukou
encukou marked this pull request as ready for review November 17, 2026 15:47
@encukou
encukou merged commit 5398a0b into python:3.14 Nov 18, 2026
135 of 139 checks passed
@miss-islington
miss-islington deleted the backport-2eb2af8-3.14 branch November 18, 2026 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants