LowGHSA-v9pg-7xvm-68hfCVE-2026-53540PYSEC-2026-3040

python-multipart: Negative Content-Length in parse_form buffers the entire body in memory

Published 15 Jun 2026 · Updated 10 Sept 2026

Is your project on an affected python-multipart?

Private repo? Upload its lockfile instead, or connect GitHub to check every repo.

Look after several Python apps? Indie watches up to 15 repos, private ones too, for $5 a month. See Indie

Affected package

Affected
<0.0.31
Fixed in
0.0.31
Update to the fixed version for your release line, for example:pip install 'python-multipart>=0.0.31'

Details

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 MultipartParser directly from the ASGI receive() stream and do not call parse_form().
  • Known parse_form() 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 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.

Is GHSA-v9pg-7xvm-68hf in any of your client repos?

Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected python-multipart, and gives you the command that fixes it.

More advisories for python-multipart

  • HighCVE-2026-53539python-multipart: Quadratic-time querystring parsing with semicolon separators causes CPU denial of service · 15 Jun 2026
  • LowCVE-2026-53538python-multipart: Semicolon treated as querystring field separator enables parameter smuggling · 15 Jun 2026
  • LowCVE-2026-53537python-multipart: Content-Disposition parameter smuggling via RFC 2231/5987 extended parameters · 15 Jun 2026
  • HighCVE-2026-42561python-multipart has Denial of Service via unbounded multipart part headers · 6 May 2026
  • MediumCVE-2026-40347python-multipart affected by Denial of Service via large multipart preamble or epilogue data · 15 Apr 2026
  • HighCVE-2026-24486Python-Multipart has Arbitrary File Write via Non-Default Configuration · 26 Jan 2026
All 9 advisories for python-multipart

References

Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.