CVE-2026-103995 python3.12: python: Misinterpretation of HTTP responses via invalid chunk parsing
Backport upstream commits 2eb2af805c15 and 9f52b443c002 (gh-150751) to fix CVE-2026-103995. Before this fix, http.client parsed Content-Length and chunk-size with int(), which also accepts signs, underscores, whitespace and 0x prefixes, so malformed framing could be misread. The patch checks these values against the RFC 9112 grammar, strips optional whitespace around Content-Length, rejects invalid chunk sizes and adds regression tests.
Upstream patches:
- https://github.com/python/cpython/commit/2eb2af805c156ca52b316bb4ced5e0ab3971d0ae.patch
- https://github.com/python/cpython/commit/9f52b443c002cccfb54bda0706a9276b6b4a109d.patch
Triage Details
Reasoning:
The Jira remote links pointed to upstream issue python/cpython#150751, PR #150752 (merged) and commits 2eb2af805c and 9f52b443c0. I fetched and checked both patches; both are real diffs to Lib/http/client.py and Lib/test/test_httplib.py, plus NEWS entries. On the cpython main branch, git log --grep=150751 returns only these two commits. Other commits to Lib/http/client.py since then are unrelated (HTTP QUERY method, tunnel host IDNA, 100-continue support). The 3.12 branch has no backport yet. The 3.13 branch has none either. The 3.14 branch has only a backport of the first commit (5398a0bf10, GH-159020). The c10s dist-git branch carries python3.12 3.12.16-2, and its upstream 3.12 http/client.py still uses the vulnerable int() parsing, with no _is_legal_content_length/_is_legal_chunk_size helpers. No shared or package-specific maintainer rules exist for python3.12. Caveats: the main-branch patches may need small context adjustments for 3.12, because main's begin() has a _max_headers parameter and other unrelated changes nearby. The NEWS files under Misc/NEWS.d can be dropped if dist-git conventions call for it. Fix Version (rhel-10.3.z) and Severity (Moderate) were already set.
Justification:
CVE-2026-103995: http.client in CPython parses the Content-Length header and the chunk-size line with plain int(). int() accepts a sign, underscores, surrounding whitespace and (for base 16) an 0x prefix, so non-hex or negative framing values are parsed when they should be rejected. That lets a client misread the HTTP response body. The python3.12 package in c10s ships 3.12.16, and its Lib/http/client.py still has the permissive code: self.length = int(length) in HTTPResponse.begin() and return int(line, 16) in _read_next_chunk_size(). Upstream commit 2eb2af805c (gh-150751, GH-150752) fixes this. It adds regexes built from the RFC 9112 grammar (_is_legal_content_length for 1DIGIT, _is_legal_chunk_size for 1HEXDIG) and checks values against them before calling int(). Commit 9f52b443c0 (GH-159156) fixes a regression caused by the first commit. The compat32 header parser keeps trailing SP/HTAB in the field value, so a header like Content-Length: 5 was treated as missing and read() blocked forever on keep-alive connections. The follow-up strips SP/HTAB as RFC 9112 section 5.1 allows and still rejects malformed values. Both commits are needed for a correct fix without a regression.
Jira: RHEL-309369
Backporting steps
I backported both upstream fixes for CVE-2026-103995 (RHEL-309369) to python3.12 3.12.16 on c10s. Both commits cherry-picked onto the base without conflicts, the package prep step succeeded and the SRPM built.
How it was done
- I checked out upstream tag
v3.12.16and applied all 9 existing dist-git patches on top, with no errors. - I cherry-picked 2eb2af805c (gh-150751, GH-150752) and then 9f52b443c0 (GH-159156). Both applied without conflicts.
- I then combined them into one patch,
00500-cve-2026-103995.patch, in the same style as the existing patches (subject00500: CVE-2026-103995, both original commit messages and both "cherry picked from" lines kept). - I dropped the two
Misc/NEWS.dfiles, following the rule to leave out news/changelog files.
What the patch changes
Lib/http/client.py:- Adds two checks that follow the RFC 9112 grammar:
_is_legal_content_length(digits only) and_is_legal_chunk_size(hex digits only). begin(): strips spaces and tabs around the Content-Length value, then only uses it if it passes the check. The oldint()with try/except and the negative-value check is gone._read_next_chunk_size(): strips trailing whitespace and rejects any chunk size that fails the check.
- Adds two checks that follow the RFC 9112 grammar:
Lib/test/test_httplib.py: addstest_malformed_content_length,test_content_length_with_whitespaceandtest_malformed_chunk_size.
Spec change
- I added
Patch500: 00500-cve-2026-103995.patchafter Patch499, with a comment block giving the CVE, both gh-150751 summaries and both upstream commit URLs. %autosetup -S git_amapplies it automatically, so no%prepchange was needed.- No existing patches, BuildRequires/Requires, Release or
%changelogwere touched.
The fix reaches the shipped package: Lib/http/client.py is installed from the source tarball, not from any prebuilt bundle.
Testing
- Package prep succeeded with the new patch.
- I ran the patched
test_httplib.pywith the system Python 3.12.15 against the patchedLib/: 150 tests ran, all passed (4 skipped), including the three new ones. - A separate quick check behaved as expected:
- Content-Length
+5,5_0and5 0are ignored (length is unset). 7and7are read as 7.- Chunk sizes
-5,+5,0x5,1_fand5raise IncompleteRead.
- Content-Length
Patch number: I picked 00500 as the next free number in this spec. It hasn't been checked against the Fedora Python patch catalog, which the spec asks to keep in sync across specfiles.
The SRPM is python3.12-3.12.16-2.el10.src.rpm.
Execution traces
⚠️ AI-Generated MR: Created by Ymir AI assistant. AI may make mistakes, select incorrect patches, or miss dependencies. Carefully review the changes. Human RHEL maintainer needs to approve this contribution before merging.By merging this MR, you agree to follow the Guidelines on Use of AI Generated Content and Guidelines for Responsible Use of AI Code Assistants.
✏️ Want to make changes to this MR?
You can check out the source branch from the fork and push your changes directly.
🔄 Retrigger Ymir
If you'd like Ymir to run again on this issue (e.g. after fixing the rules or resolving a blocker), add the ymir_todo label to the Jira issue. See the triggering docs for details.
🔧 Customize Ymir's behavior for your package
If there is anything that could be adjusted regarding Ymir's behavior and is specific to your package, you can submit an MR to gitlab.com/redhat/centos-stream/rules/python3.12. See the customization docs for details.
📞 Questions or Issues?
Contact: redhat-ymir-agent@redhat.com | Slack Forum: #forum-ymir-package-automation | Report AI Issues: Jira (project: Packit, component: jotnar) or GitHub
💡 Feedback Welcome
If you have suggestions or complaints about the quality of this MR, please reach out to us on the Slack forum where your feedback will be more visible than pinging us on individual issues. Your feedback helps us continuously improve Ymir's capabilities and deliver better results.