/

CVE-2026-48502

Severity:

HIGH RISK

(7.5)

Stack Overflow via Timestamp Parsing in MessagePack C#

CVE-2026-48502

Analyzed

Vulnerability type

Category:

Memory Allocation and Resource Exhaustion

CWE:

CWE-125, CWE-190, CWE-407, CWE-409, CWE-470, CWE-502, CWE-674, CWE-789, CWE-1188

Impact:

Denial of Service (Process Termination)

Severity:

HIGH RISK

(7.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

MessagePack for C# contains a flaw in its timestamp extension parsing where the reader allocates stack memory directly from an attacker-controlled extension length.

A crafted MessagePack payload can trigger a StackOverflowException that cannot be caught, abruptly terminating the host process whenever MessagePackReader.ReadDateTime() is invoked on malicious input.

Affected context

This vulnerability appears when applications use MessagePack for C# to parse untrusted or semi-trusted payloads and call MessagePackReader.ReadDateTime() on data that may include extension values.

In the "slow path" for timestamp extension parsing, the implementation uses the extension body length from the incoming data to compute a token size and immediately performs a stackalloc based on that value.

If the environment allows arbitrary or poorly validated MessagePack blobs to reach this parsing routine, a small malicious payload can trigger disproportionately large stack allocation before validation occurs.

Exploit preconditions

  • Attack surface: Any API or protocol that deserializes MessagePack data using MessagePack for C# and reaches ReadDateTime() on attacker-supplied input.
  • Required access: Ability to send or supply crafted MessagePack payloads to the target service (e.g., network client, message bus publisher, file uploader).
  • Trigger point: Parsing a timestamp extension where the payload claims an excessively large extension body length, invoking the slow-path timestamp parsing logic.
  • Why exploitation is possible: The implementation uses the extension body length from the wire to size a stack allocation (stackalloc) before verifying it against the expected timestamp sizes, allowing an attacker-controlled size to overrun stack limits and cause an uncatchable StackOverflowException.

Why this happens

At its core, the bug stems from trusting size metadata embedded in untrusted input and using it directly in stack-based memory allocation, without prior bounds checking.

This maps to CWE-674: Uncontrolled Resource Consumption and CWE-789: Uncontrolled Memory Allocation, where input-driven sizes can exhaust process resources.

Additional contributing aspects include CWE-190: Integer Overflow or Wraparound risk when computing token sizes, and CWE-125: Out-of-bounds Read potential if validation is bypassed.

The insecure pattern is: reading a length field from the MessagePack timestamp extension, computing tokenSize using that value, and calling stackalloc tokenSize before verifying that the claimed length matches one of the tightly constrained valid timestamp formats.

Potential impact

  • An attacker can cause immediate termination of the host process via an uncatchable StackOverflowException.
  • Critical services using MessagePack for C# may experience repeated crashes, resulting in denial of service.
  • Systems relying on high availability (APIs, microservices, background workers) can be forced into failure or continuous restart loops.
  • Chained failures in dependent services may propagate, leading to broader application or system instability.

General mitigation guidance

Effective mitigation focuses on reducing trust in input-driven size fields and avoiding stack-based allocations that can grow without strict bounds.

Pattern-based defensive measures include:

  • Validating extension lengths and timestamp sizes before any allocation, ensuring the value falls within a small, fixed set of accepted sizes.
  • Preferring fixed-size or capped allocations on the stack, and moving variable-length parsing to heap-backed buffers with explicit upper limits.
  • Introducing global limits on MessagePack payload size and per-field length constraints in deserialization routines.
  • Designing parsing code with defensive checks around length arithmetic to prevent overflow or exaggerated sizes.
  • Running services with health monitoring and graceful restart mechanisms, limiting the blast radius of unexpected process termination.

How teams detect issues like this

Detection typically involves a combination of code-level inspection and runtime observability:

  • Static analysis rules that flag stackalloc or other stack-based allocations driven directly by input-derived lengths or extension values.
  • Targeted code review of MessagePack parsing routines, focusing on any path where extension lengths, timestamps, or variable-length fields are used in memory allocation before validation.
  • Runtime monitoring and logging for recurring StackOverflowException events, crashes, or abnormal termination patterns when deserializing MessagePack data.
  • Policy-based checks in CI/CD that require explicit bounds checking around all computed sizes in serialization/deserialization libraries.
  • Optional use of automated analyzers that recognize common resource exhaustion patterns and unsafe size handling in C# code.

Sources

SourceLink
github.comgithub.com/MessagePack-CSharp/MessagePack-CSharp/security/advisories/GHSA-382j-8mxh-c7x2

Frequently asked

questions

It is exploitable wherever MessagePack for C# deserializes data from potentially hostile or untrusted sources and invokes ReadDateTime() on attacker-controlled content. Public-facing services, message consumers, and APIs using MessagePack may be affected.

An attacker only needs the ability to supply crafted MessagePack payloads to the vulnerable parsing routine. No local code execution or privileged system access is required; network or logical access to the MessagePack endpoint is sufficient.

The safest approach is to validate all extension lengths and timestamp sizes against a strict, predefined set of allowed values before performing any stack allocation or buffer creation. Additionally, avoid using input-controlled sizes in stackalloc and enforce upper bounds on all parsed lengths.

Adopt defensive parsing patterns: treat all input-derived sizes as untrusted, apply strict bounds and sanity checks, prefer fixed-size or capped buffers, and incorporate static analysis rules to flag unsafe memory allocations. Regular security-focused code reviews of serialization/deserialization code paths help catch comparable flaws early.

Find out what's already
exploitable in your codebase.