CVE-2026-114613: MessagePack: Unbounded memory leak in msgpack C extension on strict_map_key validation failure
Impact
The msgpack-python C extension (msgpack.cmsgpack) leaks a decoded map value when deserialization rejects a key with strictmapkey=True (the default). Repeated malformed inputs can cause unbounded process memory growth and denial of service in applications that deserialize attacker-controlled MessagePack data. Both unpackb() and the streaming Unpacker API are affected. The pure-Python fallback does not exhibit this leak in the reported tests.
The report measured approximately 4 MiB retained per failed parse and 100 MiB after 25 failed parses on Windows with Python 3.14 and msgpack 1.2.2. These are reporter-provided results.
Additional impact: stale parser-stack references
The reference-ownership audit performed while fixing this leak found an additional memory-safety issue in the streaming Unpacker.
After unpack() completed a nested container, an inactive parser-stack slot could retain a non-owning pointer to the decoded object. A subsequent skip() could reactivate that slot. If parsing then failed, context cleanup treated the stale pointer as an owned reference and decremented it.
This corrupts the object's reference count and can result in a use-after-free or double PyDECREF when its actual owners later release it.
Although few users use this API, but those who do may experience crashes or unexpected errors due to a use-after-free.
Details
In msgpack/unpack.h, unpackcallbackmapitem() rejects keys that are neither str nor bytes. At this point the map value has already been constructed. The early error return does not release the value reference.
In msgpack/unpacktemplate.h, the value is held in the local obj in unpackexecute(). The CTMAPVALUE error path jumps to failed without decrementing that reference. Cleanup of the parser stack does not recover the value because it is not stored in the stack. The fallback checks the key before decoding the value.
Affected versions
The report reproduces the issue on 1.2.2 and reports it on development commit 475c1b7. The affected-product field lists the reproduced release only; it is not a claim that earlier releases are unaffected.
The earliest affected release needs confirmation: the report's summary says 1.1.x through 1.2.2, while its root-cause analysis attributes introduction to commit cd81370 (PR #673). Resolve this discrepancy before publishing a definitive affected-version range.
Reproduction
Run in a disposable local process with the C extension installed:
python import msgpack
payload = msgpack.packb({42: b"A" (4 1024 1024)}, usebintype=True) msgpack.unpackb(payload) # Raises ValueError; the report observes a 4 MiB leak.
Streaming API trigger:
python import msgpack
payload = msgpack.packb({42: b"A" (4 1024 1024)}, usebintype=True) u = msgpack.Unpacker() u.feed(payload) list(u) # Same strictmapkey error path.
Workarounds
The pure-Python fallback is reported not to leak on this path and may be used as a temporary workaround after application compatibility and performance checks. Request-size and rate limits may reduce the impact but do not eliminate cumulative leakage.
Other sources
MessagePack is the serializer implementation for Python msgpack.org. Prior to 1.2.3, the msgpack-python C extension (msgpack.cmsgpack) leaks a decoded map value when deserialization rejects a key with strictmapkey=True (the default). Repeated malformed inputs can cause unbounded process memory growth and denial of service in applications that deserialize attacker-controlled MessagePack data. Both unpackb() and the streaming Unpacker API are affected. The pure-Python fallback does not exhibit this leak in the reported tests. This issue is fixed in version 1.2.3.
— MITRE
MessagePack: Unbounded memory leak in msgpack C extension on strictmapkey validation failure
— Microsoft
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/msgpackto a version that resolves this vulnerability.Fixed in 1.2.3 - Upgrade
Upgrade
azurelinux/python-msgpackto a version that resolves this vulnerability.Fixed in 1.2.3-1 - Upgrade
Upgrade
msgpack-pythonto a version that resolves this vulnerability.Fixed in 1.2.3 - Configuration
Use the pure-Python fallback instead of the C extension as a temporary workaround, after checking application compatibility and performance.
msgpack-python implementation = pure-Python fallback - Compensating control
Apply request-size and rate limits to reduce the impact of repeated malformed MessagePack inputs; these controls do not eliminate cumulative leakage.
Event History
Frequently Asked Questions
Which deployments are exposed to this denial-of-service condition?
Applications using msgpack-python versions before 1.2.3 with the msgpack._cmsgpack C extension are affected when they deserialize attacker-controlled MessagePack input. The pure-Python fallback did not exhibit the leak in the reported tests.
Does an application need to enable a non-default option to be affected?
No. The leak is triggered when strict_map_key=True rejects a decoded map key, and strict_map_key=True is the default.
Which MessagePack interfaces can trigger the leak?
Both unpackb() and the streaming Unpacker API are affected. Repeated malformed inputs can cause unbounded process memory growth.
What can be done if upgrading immediately is not possible?
Avoid deserializing attacker-controlled MessagePack data with the affected C extension, or use the pure-Python fallback, which did not exhibit this leak in the reported tests. Upgrade to msgpack-python 1.2.3 when possible.