GitHub Advisoryadvisory · PyPI
GHSA-54p9-h82j-f925 Multidict: Reference leak in CIMultiDict/MultiDict items-view union and subtraction
MEDIUM
Official page ↗
- Aliases
- CVE-2026-104874
- Ecosystem
- PyPI
- Packages
- multidict
- Severity
- Moderate
- CVSS vector
- CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L
- Weaknesses
- CWE-401
- Reviewed
- 2026-10-05
Affected packages
• PyPI multidict: >= 6.7.0, < 6.9.1 → fixed in 6.9.1
Description
Description
A reference leak in the items-view union and subtraction operators of aio-libs/multidict 6.7.0 through 6.9.0 (C extension) lets a remote client drive unbounded, unreclaimable memory growth by having each operand element leak one key-identity object and one value object. The reflected-union path (`operand | d.items()`, `multidict_itemsview_or2_impl`) and the subtraction path (`d.items() - operand`, `multidict_itemsview_sub1_impl`) parse each element into new strong references but release only the tuple wrapper, never the identity and value. Servers in the aio-libs stack build these views over attacker-supplied HTTP headers and query strings, so the operand size is under remote control. Forced garbage collection does not recover the leaked objects, so resident memory rises monotonically until the process is killed.
---
Root Cause
`_multidict_itemsview_parse_item()` returns new references: a fresh identity via `md_calc_identity()` and a fresh value via `Py_NewRef()`. The `or2_impl` first parse loop requests both but clears only `arg`:
```c
// views.h:565 — or2_impl first parse loop
while ((st = PyIter_NextItem(iter, &arg)) > 0) {
int tmp = _multidict_itemsview_parse_item(
self, arg, &identity, NULL, &value); // identity + value: new refs
if (tmp 0) {
if (_set_add(tmp_set, identity, value) 9,} elements: RSS = {rss_mb():.1f} MB")
```
Execution Steps
1. `python3 -m venv venv` (CPython 3.10+).
2. `./venv/bin/pip install "multidict==6.9.0"` (installs the C-extension wheel).
3. From a directory that is not a multidict checkout, run each script with `./venv/bin/python`.
Actual Execution Evidence
```
[or2 operand | items] leaked strong refs = 100000
[sub1 items - operand] leaked strong refs = 100000
[and2 items & operand] leaked strong refs = 0 <- control
```
```
operand | d.items() (or2) leaked=50000
d.items() | operand (or1) leaked=0
d.items() - operand (sub1) leaked=50000
operand - d.items() (rsub) leaked=0
d.items() & operand (and) leaked=0
```
```
start RSS = 15.6 MB
after 2,000,000 elements: RSS = 288.1 MB
after 6,000,000 elements: RSS = 776.8 MB
after 10,000,000 elements: RSS = 1266.8 MB (gc.collect() every iteration)
```
Version-boundary evidence
Same `poc_dispatch.py`, PyPI wheels, identical environment. Last-clean is `6.6.4`; first-affected is `6.7.0`:
```
6.6.4 : or2=0 sub1=0 others=0 (clean, last 6.6.x)
6.7.0 : or2=50000 sub1=50000 others=0 (AFFECTED, first)
6.9.0 : or2=50000 sub1=50000 others=0 (affected)
```
The clean 6.6.x releases return correct set-operation results, so the zero leak reflects correct memory management, not a broken path.
Analysis of Results
The operand holds exactly `N` references to one sentinel value; after the union its refcount rises by another `N` and stays there post-GC, so each element leaked one strong reference. Subtraction shows the identical delta. The intersection control, which clears `identity` and `value`, leaks zero; the only code difference is the two missing `Py_CLEAR` calls, so the leak is caused by that omission and not the harness. RSS climbs from 15.6 MB to 1266.8 MB (~250 MB per 2M elements) despite per-iteration GC, confirming the objects are unreachable by the cyclic collector.
---
Impact
A process that evaluates items-view unions or subtractions over remote-influenced operands leaks one identity plus one value object per element, permanently. In the aio-libs stack multidict backs HTTP headers and query strings, so an attacker who enlarges the operand (for example, many repeated header items compared against a fixed allow/deny set) forces steady, unrecoverable heap growth and can eventually exhaust memory in a long-lived server. This is an availability defect only; results stay correct and no data is exposed.
Reachability depends on the application evaluating `operand | view.items()` (reflected union) or `view.items() - operand` (subtraction) over a sequence of 2-tuples whose count is remote-influenced. The forward union `view.items() | operand` routes to `or1_impl`, which clears correctly and does not leak; a non-tuple operand element takes the `parse_item` early-return and does not leak. Set algebra over items views is not the most common multidict usage, which bounds exposure and is why this is Medium, not High. This is distinct from PR #1413, which fixed a temporary-tuple leak in the second loop and did …
Related
Alias · CVE (1)
- CVE-2026-104874 Multidict is an implementation of a multidict data structure. vulnerability
Weakness · CWE (1)
- CWE-401 Missing Release of Memory after Effective Lifetime weakness
References
- https://github.com/aio-libs/multidict/security/advisories/GHSA-54p9-h82j-f925 web
- https://nvd.nist.gov/vuln/detail/CVE-2026-104874 advisory
- https://github.com/aio-libs/multidict/commit/350b4a07bf8ff851b6d7544e81b1c748bdc74c40 web
- https://github.com/aio-libs/multidict package
- https://github.com/aio-libs/multidict/releases/tag/v6.9.1 web