
PEACH
Un framework di isolamento del tenant
The streaming C-extension msgpack.Unpacker preallocates arrays from attacker-controlled element counts, with each nested container allocated independently. Under the default limits, a few kilobytes of MessagePack headers can reserve hundreds of gigabytes of virtual memory and cause denial of service in environments with address-space limits. unpackb() and the pure-Python fallback are not affected.
https://github.com/msgpack/msgpack-python (release v1.2.3)
msgpack/unpack.h:128-140 — unpack_callback_array(): bounds check at :130, allocation sink PyList_New(n) / PyTuple_New(n) at :134msgpack/unpack.h:166-183 — unpack_callback_map(): PyList_New(n) at :174 when object_pairs_hook is setmsgpack/unpack.h:19 — MSGPACK_EMBED_STACK_SIZE (1024)msgpack/unpack_template.h:117-129 — start_container() macro: depth guard at :118, goto _header_again at :129msgpack/unpack_template.h:299-301 — CS_ARRAY_32 handler (carries the upstream /* FIXME security guard */ comment at :300)msgpack/unpack_template.h:305-307 — CS_MAP_32 handler (same comment at :306)msgpack/_unpacker.pyx:375-376 — Unpacker.__init__: max_array_len = max_buffer_sizemsgpack/_unpacker.pyx:378 — Unpacker.__init__: max_map_len = max_buffer_size // 2The MessagePack wire format encodes a container as a header declaring an element count, followed by the elements themselves. The C extension msgpack._cmsgpack preallocates the result container from that declared count before any element has been read, so the allocation size is chosen by attacker-controlled input while the bytes that would justify it never have to be supplied. This is an uncontrolled resource-allocation pattern (CWE-789): the cost to the victim is unbounded by the cost to the attacker.
The only bound on the declared count is n > u->max_array_len at msgpack/unpack.h:130. For the streaming Unpacker, max_array_len defaults to max_buffer_size at msgpack/_unpacker.pyx:375-376 — that is, 104 857 600 elements, because the 100 MiB value is applied as an element count and is never divided by the 8-byte pointer size of a PyObject* slot. A single accepted array32 header therefore commits roughly 800 MB of pointer slots from five bytes on the wire.
The amplification compounds with nesting. After allocating a container, start_container() pushes the parser stack and jumps back to the header parser (msgpack/unpack_template.h:117-129), so each nested array32 header repeats the allocation at the next level. The only depth bound is MSGPACK_EMBED_STACK_SIZE = 1024 (msgpack/unpack.h:19), checked at msgpack/unpack_template.h:118. The effective memory ceiling of a default-configured Unpacker is consequently max_array_len * sizeof(void*) * MSGPACK_EMBED_STACK_SIZE — approximately 800 GB — rather than the 100 MiB a reader of max_buffer_size would expect.
max_buffer_size is not wholly inert: it still bounds the number of bytes the Unpacker will buffer, so reaching the depth limit requires max_buffer_size >= 5 * depth. Because max_array_len is derived from it, however, the two bounds are coupled rather than independent — a budget of B bytes permits B / 5 levels of nesting, each preallocating up to B * 8 bytes, for a worst case of roughly 1.6 * B**2 bytes, capped by the 1024-level stack limit. At the default B = 104857600 the payload bound is never the binding constraint, since 5 KB of headers exhausts the stack depth while remaining five orders of magnitude below the 100 MiB buffer ceiling.
The reference-ownership rewrite shipped in v1.2.3 (unpack_take_ref(), ctx->result, the Py_XDECREF(obj) added at the _end label) addresses reference ownership on error paths and does not alter this behaviour: start_container() still invokes the allocating callback once per level and still increments top, and the depth guard at msgpack/unpack_template.h:118 is unchanged from prior releases.
The exposure is specific to the streaming API. unpackb() is not affected: it derives max_array_len from the actual payload length at msgpack/_unpacker.pyx:183-184, so a declared count can never exceed the bytes supplied. Maps are not affected in the default configuration, because unpack_callback_map() allocates with PyDict_New(), which does not preallocate; they become affected when object_pairs_hook is in use, as that path allocates PyList_New(n) at msgpack/unpack.h:174 under the max_map_len bound (max_buffer_size // 2).
The project README documents max_buffer_size as one of two defences for untrusted input, stating that it "limits the internal buffer size" and "is also used to limit preallocated list sizes". That statement holds only in units of elements and only at a single nesting level; the byte figure a caller actually gets is larger by the pointer size and again by the nesting depth. Callers following the documented streaming pattern with the documented defence in place remain exposed.
Low. The attack requires no authentication, no privileges, no user interaction, and no race or timing window. It is effective against the default configuration of a documented public API — the attacker needs only the ability to supply bytes that reach Unpacker.feed() or a file-like object passed to the Unpacker constructor, which is the ordinary condition of any service deserializing MessagePack from a network peer. The payload is a few kilobytes of repeated five-byte container headers and requires no knowledge of the target application beyond its use of the streaming unpacker.
Setting max_array_len explicitly is not by itself sufficient: because the limit is applied per nesting level, the effective ceiling remains max_array_len * sizeof(void*) * MSGPACK_EMBED_STACK_SIZE. A configuration of max_array_len=1000000 — a plausible choice for an application handling large arrays — still permits approximately 7.8 GB of preallocation from a 5 KB payload. Only values at or below tolerance / (sizeof(void*) * MSGPACK_EMBED_STACK_SIZE) bound the allocation to tolerance, which is 12 800 elements for a 100 MiB ceiling. Neither the README nor the parameter's docstring states this relationship, so a conscientious attempt to configure the limit is likely to leave the application exposed by three orders of magnitude.
Found by OSTIF using AI with their own harness.
Manually verified, fixed, and reported by Shielder.
Run against msgpack==1.2.3; confirm msgpack.Unpacker.__module__ is msgpack._cmsgpack, since the pure-Python fallback is unaffected. Scaled to max_buffer_size=1_000_000, so max_array_len is 1 000 000 elements and each accepted header costs 8 MB instead of the default 800 MB.
array32 header declaring exactly max_array_len elements and measure it with tracemalloc:payload = b"\xdd" + struct.pack(">I", 1_000_000) # 5 bytes
u = msgpack.Unpacker(max_buffer_size=1_000_000)
u.feed(payload); next(u) # StopIteration; already allocatedFive bytes commit 8.6 MB. This is the sanctioned maximum, not an overflow: declaring 1_000_001 instead is rejected with ValueError: 1000001 exceeds max_array_len(1000000), so the single allocation above is precisely what the configured limit permits.depth times, so every level presents the identical, individually-legal count to the identical check at msgpack/unpack.h:130:payload = (b"\xdd" + struct.pack(">I", 1_000_000)) * depth| depth | input | committed |
|---|---|---|
| 1 | 5 B | 8.6 MB |
| 10 | 50 B | 77.3 MB |
| 100 | 500 B | 763.9 MB |
| 1000 | 5 000 B | 7 630.4 MB |
Every header passes the guard, no header is larger than the limit allows, and the total is bounded by nothing. Growth is linear in depth to within one percent of depth × max_array_len × sizeof(void*), and StackError arrives only at depth 1025 — the parser stack is the sole ceiling, never memory. |
max_buffer_size of 100 MiB, max_array_len is 104 857 600 elements, so one legal header costs 800 MB and the 1024-level stack permits roughly 859 GB from a 5 120-byte payload. unpackb() is immune throughout, rejecting every payload above with ValueError: 1000000 exceeds max_array_len(200) because it derives the limit from the input length.MemoryError from 5 000 bytes of input:docker run --rm python:3.13-slim sh -c 'pip install -q msgpack==1.2.3 && ulimit -v 524288 && python -c "\
import struct, msgpack
p = (b\"\\xdd\" + struct.pack(\">I\", 1_000_000)) * 1000
u = msgpack.Unpacker(max_buffer_size=1_000_000); u.feed(p)
next(u)"'An unauthenticated attacker who can deliver bytes to any application that streams untrusted MessagePack through Unpacker can force the process to commit arbitrarily large amounts of memory from a negligible amount of network traffic. Measured against v1.2.3 on a scaled configuration, consumption tracks depth * max_array_len * sizeof(void*) to within one percent across nesting depths of 10 to 200 — a 200-byte payload commits 306 MB, an amplification factor of roughly 1.6 million to one — and the parser aborts with StackError only once the 1024-level stack limit is reached. The outcome depends on how the host accounts for memory, and the distinction matters for reproduction. Where an address-space ceiling applies — RLIMIT_AS / ulimit -v, strict overcommit (vm.overcommit_memory=2), Windows commit charge, or a 32-bit address space — the reservation is refused and a MemoryError is raised inside the deserialization path, failing the request and, in a single-threaded server, the connection handling it. Where no such ceiling applies, the allocation succeeds as reserved address space: PyList_New() receives zero-filled pages that the attack never writes to, so resident memory stays low and the process is not OOM-killed, and the damage is address-space and page-table pressure rather than termination. A cgroup or container memory limit alone therefore does not stop this, and testing under one will appear to show no impact — verified against v1.2.3, where a parse demanding 1 525 MB completed normally inside a 256 MB container but raised MemoryError under a 512 MB ulimit -v.
Because the allocation happens before any element is read, the attacker never needs to send the data the allocation nominally accounts for, and no per-request size or rate limit sized against the payload will bound the memory consumed. Impact is confined to the availability of the deserializing process; no confidentiality or integrity property is affected.
Fonte: NVD
Valutazione gratuita delle vulnerabilità
Valuta le tue pratiche di sicurezza del cloud in 9 domini di sicurezza per stabilire un benchmark del tuo livello di rischio e identificare le lacune nelle tue difese.
Richiedi una demo personalizzata
"La migliore esperienza utente che abbia mai visto offre piena visibilità ai carichi di lavoro cloud."
"Wiz fornisce un unico pannello di controllo per vedere cosa sta succedendo nei nostri ambienti cloud."
"Sappiamo che se Wiz identifica qualcosa come critico, in realtà lo è."