CVE-2026-53540: Python-Multipart: Negative Content-Length in parse_form buffers the entire body in memory

Published Jun 15, 2026
·
Updated

Summary

parseform() 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

parseform() 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(contentlength - bytesread, chunksize). The header value was parsed to an integer without checking its sign, so a Content-Length of -1 made this expression negative, and inputstream.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 parseform() 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 MultipartParser directly from the ASGI receive() stream and do not call parseform(). Known parseform() consumers either do not forward Content-Length to it, recompute it from the already-read body, or run behind a layer (such as Werkzeug) that normalizes a negative Content-Length to 0.

The realistic exposure is limited to bespoke WSGI or http.server handlers that forward raw client headers into parseform(). 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.

Other sources

Python-Multipart is a streaming multipart parser for Python. Prior to 0.0.31, parseform() 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. This vulnerability is fixed in 0.0.31.

MITRE

Affected Software

2 affected componentsFixes available
pip/python-multipart<0.0.31
0.0.31
Fastapiexpert Python-multipart Python<0.0.31

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade pip/python-multipart to a version that resolves this vulnerability.

    Fixed in 0.0.31
  2. Upgrade

    Upgrade Python-Multipart to a version that resolves this vulnerability.

    Fixed in 0.0.31
  3. Operational

    Verify that any code paths calling Python-Multipart's parse_form() do not pass a negative Content-Length value from attacker-controlled headers; upgrade to 0.0.31+ where parse_form() rejects a negative Content-Length with a ValueError before reading the stream.

Event History

Jun 15, 2026
Advisory Published
via GitHub·08:23 PM
Data Sourced
via GitHub·08:23 PM
DescriptionSeverityWeaknessAffected Software
Jun 22, 2026
CVE Published
via MITRE·04:58 PM
Data Sourced
via MITRE·04:58 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·06:16 PM
DescriptionSeverityWeaknessAffected Software
Free Weekly Intel

Don't miss critical vulnerabilities

Join thousands of security professionals who receive our weekly digest of trending CVEs, zero-days, and exploited vulnerabilities.

No spam. Unsubscribe anytime.

Frequently Asked Questions

1

What is the severity of CVE-2026-53540?

The severity of CVE-2026-53540 is classified as low with a score of 3.7.

2

What are the potential risks associated with CVE-2026-53540?

CVE-2026-53540 could lead to excessive memory consumption due to reading the entire request body into memory.

3

How do I fix CVE-2026-53540?

To fix CVE-2026-53540, ensure that the `Content-Length` header is properly validated before using it in the `parse_form()` function.

4

Which software is affected by CVE-2026-53540?

CVE-2026-53540 affects the `pip/python-multipart` software.

5

When was CVE-2026-53540 published?

CVE-2026-53540 was published on June 15, 2026.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203