python-multipart: Negative Content-Length in parse_form buffers the entire body in memory
Description
Summary
parse_form() did not validate the Content-Length header before using it to bound its chunked read of the request body. A negative Content-Length turned the bounded read into a read-until-EOF, so the entire body was loaded into memory in a single read instead of in fixed-size chunks.
Details
parse_form() reads the input stream in chunks, never reading more than the remaining Content-Length at a time. The per-chunk size is computed as min(content_length - bytes_read, chunk_size). The header value was parsed to an integer without checking its sign, so a Content-Length of -1 made this expression negative, and input_stream.read(-1) reads until end of stream. The intended bounded, chunked read therefore collapsed into a single unbounded read of the whole stream. The amount read is still bounded by what the client actually sends.
Impact
This only affects code that calls parse_form() directly with a Content-Length header taken from attacker-controlled input and without normalizing a negative value first. No known package is affected:
- Starlette and FastAPI drive
MultipartParserdirectly from the ASGIreceive()stream and do not callparse_form(). - Known
parse_form()consumers either do not forwardContent-Lengthto it, recompute it from the already-read body, or run behind a layer (such as Werkzeug) that normalizes a negativeContent-Lengthto0.
The realistic exposure is limited to bespoke WSGI or http.server handlers that forward raw client headers into parse_form(). In that case a crafted request buffers the body in memory at once, degrading availability under concurrent requests rather than causing a complete denial of service.
Mitigation
Upgrade to version 0.0.31 or later, which rejects a negative Content-Length with a ValueError before reading the stream.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
python-multipartPyPI | < 0.0.31 | 0.0.31 |
Affected products
10- Range: < 0.0.31
- osv-coords9 versionspkg:apk/chainguard/airflow-3pkg:apk/chainguard/airflow-core-3pkg:apk/chainguard/litellmpkg:apk/chainguard/tritonserver-backend-vllm-cuda-12.9pkg:apk/chainguard/wazuh-manager-frameworkpkg:apk/chainguard/wazuh-manager-framework-fipspkg:apk/wolfi/airflow-3pkg:pypi/python-multipartpkg:rpm/opensuse/python-python-multipart&distro=openSUSE%20Tumbleweed
< 3.2.2-r7+ 8 more
- (no CPE)range: < 3.2.2-r7
- (no CPE)range: < 3.2.2-r7
- (no CPE)range: < 1.89.0-r2
- (no CPE)range: < 25.9.0_git20260617-r0
- (no CPE)range: < 4.14.5-r4
- (no CPE)range: < 4.14.5-r6
- (no CPE)range: < 3.2.2-r7
- (no CPE)range: < 0.0.31
- (no CPE)range: < 0.0.32-1.1
Patches
Vulnerability mechanics
References
2News mentions
0No linked articles in our index yet.