---
schema_version: '1.0'
id: security-20260812-bd4429
title: 'CVE-2026-53540: python-multipart: Negative Content-Length in parse_form buffers
  the entire body in memory'
url: https://osv.dev/vulnerability/PYSEC-2026-3040
url_hash: bd4429b0b1e5c4c379308335a0d7d0d45acf9c10e8fb3c81160b4da6b32c7b80
canonical_url: https://osv.dev/vulnerability/PYSEC-2026-3040
source: osv:pypa
category: security/library
category_raw: cve/library
region: null
tags:
- cve
- CVE-2026-53540
- PYSEC-2026-3040
- severity:CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L
- python-multipart
- PyPI
lang: en
published_at: '2026-07-13T15:46:17Z'
fetched_at: '2026-08-12T16:00:04.818481Z'
updated_at: '2026-08-22T14:53:00Z'
status: published
content_hash: e86a8cca3c822697ce327ea9d911e5d3f98a733c86766c378e6ea653c162eecd
content_changed_at: '2026-08-22T13:15:21.977356Z'
license_note: full
summary: 'python-multipart: Negative Content-Length in parse_form buffers the entire
  body in memory'
summary_source: rss
summary_en: 'python-multipart: Negative Content-Length in parse_form buffers the entire
  body in memory'
summary_omitted_reason: null
redistribution: true
keywords_en:
- body
- buffers
- Content-Length
- CVE
- CVE-2026-53540
- entire
- library vulnerability
- memory
- Negative
- parse_form
- Parseable
- PyPI
- PYSEC-2026-3040
- python-multipart
- severity:CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L
- software security
- the
entities_en:
- name: CVE
  type: data
- name: Parseable
  type: organization
- name: PyPI
  type: artifact
topics_en:
- library vulnerability
- software security
numeric_facts: []
entities:
- name: CVE
  type: data
- name: PyPI
  type: artifact
- name: Parseable
  type: organization
related_auto:
- name: Portal
  type: organization
  weight: 1.0
- name: Hugging Face
  type: organization
  weight: 1.0
computed_at: '2026-08-22T14:52:49Z'
---

# CVE-2026-53540: python-multipart: Negative Content-Length in parse_form buffers the entire body in memory

## TL;DR
python-multipart: Negative Content-Length in parse_form buffers the entire body in memory

## Key Points
- cve / CVE-2026-53540 / PYSEC-2026-3040 / severity:CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L / python-multipart / PyPI

## Details
**Severity:** CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L
**Advisory:** PYSEC-2026-3040 (CVE-2026-53540)

**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.

**References:**
- https://github.com/Kludex/python-multipart/security/advisories/GHSA-v9pg-7xvm-68hf
- https://github.com/Kludex/python-multipart
- https://pypi.org/project/python-multipart
- https://github.com/advisories/GHSA-v9pg-7xvm-68hf
- https://nvd.nist.gov/vuln/detail/CVE-2026-53540

_Data: OSV.dev (upstream: pypa) — https://osv.dev/vulnerability/PYSEC-2026-3040_

## Source
元記事: [CVE-2026-53540: python-multipart: Negative Content-Length in parse_form buffers the entire body in memory](https://osv.dev/vulnerability/PYSEC-2026-3040) — published 2026-07-13T15:46:17Z
